From 25f0c11a25a8124b43d95fddc68d56ada3f079c9 Mon Sep 17 00:00:00 2001 From: jinny-l Date: Wed, 30 Aug 2023 20:54:35 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feat:=208=EC=9B=94=2030=EC=9D=BC=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98=EB=A8=B8=EC=8A=A4=20?= =?UTF-8?q?=EC=98=A4=ED=94=88=EC=B1=84=ED=8C=85=EB=B0=A9=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\261\204\355\214\205\353\260\251.java" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "jinny-l/season2/_230830/PGS_\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.java" 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; + } +}