diff --git "a/jinny-l/season2/_230830/PGS_\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.java" "b/jinny-l/season2/_230830/PGS_\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.java" new file mode 100644 index 0000000..cda302b --- /dev/null +++ "b/jinny-l/season2/_230830/PGS_\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.java" @@ -0,0 +1,55 @@ +package season2._230830; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class PGS_오픈채팅방 { + + public static String[] solution(String[] record) { + List answer = new ArrayList<>(); + List actionLog = new ArrayList<>(); + List userLog = new ArrayList<>(); + Map users = new LinkedHashMap<>(); + + for (String s : record) { + // record 파싱 + String[] tmp = s.split(" "); + String action = tmp[0]; + String userId = tmp[1]; + + // 로그 저장 + actionLog.add(action); + userLog.add(userId); + + // 변경되는 유저 정보 저장 + if (action.equals("Change") || action.equals("Enter")) { + String name = tmp[2]; + users.put(userId, name); + } + } + + // 로그를 기록으로 변환 + for (int i = 0; i < actionLog.size(); i++) { + String action = actionLog.get(i); + String userId = userLog.get(i); + String name = users.get(userId); + String log = generateLog(action, name); + if (log != null) { + answer.add(log); + } + } + return answer.toArray(new String[]{}); + } + + private static String generateLog(String action, String name) { + if (action.equals("Enter")) { + return String.format("%s님이 들어왔습니다.", name); + } + if (action.equals("Leave")) { + return String.format("%s님이 나갔습니다.", name); + } + return null; + } +}