Skip to content

Commit 5ce8805

Browse files
authored
Merge pull request #330 from zzzyoonnn/main
[Solved] PRG_오픈채팅방
2 parents 5373c6a + 9b18b70 commit 5ce8805

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Week12/오픈채팅방/jiyoon.java

+31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
11
package Week12.오픈채팅방;
2+
import java.util.*;
23

34
public class jiyoon {
5+
class Solution {
6+
public Object[] solution(String[] record) {
7+
HashMap<String, String> ID = new HashMap<>(); // Key : id, Value : nickname
8+
for (String s : record) {
9+
String[] arr = s.split(" ");
10+
11+
// 첫 단어가 Leave가 아니라면 ID map 저장
12+
if (!arr[0].equals("Leave")) {
13+
ID.put(arr[1], arr[2]);
14+
}
15+
}
16+
17+
// 메시지를 저장할 ArrayList 생성
18+
ArrayList<String> list = new ArrayList<>();
19+
for (String s : record) {
20+
String[] arr = s.split(" ");
21+
22+
// 첫 단어가 Change가 아니라면 list에 추가
23+
if (arr[0].equals("Enter")) {
24+
list.add(ID.get(arr[1]) + "님이 들어왔습니다.");
25+
} else if (arr[0].equals("Leave")) {
26+
list.add(ID.get(arr[1]) + "님이 나갔습니다.");
27+
}
28+
}
29+
30+
// ArrayList -> Array로 변환
31+
Object[] answer = list.toArray();
32+
return answer;
33+
}
34+
}
435
}

0 commit comments

Comments
 (0)