[Programmers] 오픈채팅방 - 2019 KAKAO BLIND RECRUITMENT

동민·2021년 3월 11일
import java.util.LinkedHashMap;
import java.util.ArrayList;

// 오픈채팅방 - 2019 KAKAO BLIND RECRUITMENT
public class OpenChatting {
	public String[] solution(String[] record) {
		ArrayList<String> list = new ArrayList<>();
		LinkedHashMap<String, String> map = new LinkedHashMap<>();

		for (String ele : record) {
			String[] str = ele.split(" ");
			if (str[0].equals("Enter") || str[0].equals("Change")) {
				map.put(str[1], str[2]);
			}

		}

		for (String ele : record) {
			String[] str = ele.split(" ");
			if (str[0].equals("Enter")) {
				list.add(map.get(str[1]) + "님이 들어왔습니다.");
			} else if (str[0].equals("Leave")) {
				list.add(map.get(str[1]) + "님이 나갔습니다.");
			}
		}

		String[] answer = new String[list.size()];
		for (int i = 0; i < list.size(); i++) {
			answer[i] = list.get(i);
		}

		return answer;
	}

	public static void main(String[] args) {

		OpenChatting s = new OpenChatting();
		String[] record = { "Enter uid1234 Muzi", "Enter uid4567 Prodo", "Leave uid1234", "Enter uid1234 Prodo", "Change uid4567 Ryan" };
		
		s.solution(record); // "Prodo님이 들어왔습니다.", "Ryan님이 들어왔습니다.", "Prodo님이 나갔습니다.", "Prodo님이 들어왔습니다."
	}
}
profile
BE Developer

0개의 댓글