원본 : https://programmers.co.kr/learn/courses/30/lessons/42888
코딩테스트 연습 - 오픈채팅방
오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오
programmers.co.kr
풀이
import java.util.*;
class Solution {
public String[] solution(String[] record) {
Map<String, String> user = new HashMap<>();
int cnt = 0;
for (String str : record) {
String[] strSplit = str.split(" ");
if ("Enter".equals(strSplit[0])) {
user.put(strSplit[1], strSplit[2]);
cnt++;
} else if ("Change".equals(strSplit[0])) {
user.replace(strSplit[1], strSplit[2]);
} else {
cnt++;
}
}
String[] answer = new String[cnt];
int idx = 0;
for (String str : record) {
String[] strSplit = str.split(" ");
if ("Enter".equals(strSplit[0])) {
answer[idx++] = user.get(strSplit[1]) + "님이 들어왔습니다.";
} else if ("Leave".equals(strSplit[0])) {
answer[idx++] = user.get(strSplit[1]) + "님이 나갔습니다.";
}
}
return answer;
}
}
단체사진 찍기 (2017 카카오코드 본선) (0) | 2022.06.30 |
---|---|
카카오프렌즈 컬러링북 (2017 카카오코드 예선) (0) | 2022.06.30 |
문자열 압축 (2020 KAKAO BLIND RECRUITMENT) (0) | 2022.06.30 |
행렬의 덧셈 (연습문제) (0) | 2022.06.30 |
핸드폰 번호 가리기 (연습문제) (0) | 2022.06.30 |
댓글 영역