From f692c872d5de5d0cd15d6402302e124bb3009805 Mon Sep 17 00:00:00 2001 From: yubin Date: Thu, 8 Aug 2024 22:29:38 +0900 Subject: [PATCH] 57-xxubin04 --- xxubin04/README.md | 4 +- ...10\354\261\204\355\214\205\353\260\251.py" | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 "xxubin04/\355\225\264\354\213\234\353\247\265/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.py" diff --git a/xxubin04/README.md b/xxubin04/README.md index c17d154..b30d0f6 100644 --- a/xxubin04/README.md +++ b/xxubin04/README.md @@ -56,4 +56,6 @@ | 52차시 | 2024.07.05 | 구현 | [2019 카카오 인턴십]튜플 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/198 | | 53차시 | 2024.07.08 | DP | [2193]이친수 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/200 | | 54차시 | 2024.07.11 | Tree | [1991]트리 순회 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/203 | -| 55차시 | 2024.07.29 | 정렬 | [Programmers]H-Index | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/208 | \ No newline at end of file +| 55차시 | 2024.07.29 | 정렬 | [Programmers]H-Index | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/208 | +| 56차시 | 2024.08.05 | 구현 | [2018 KAKAO BLIND]뉴스 클러스터링 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/211 | +| 57차시 | 2024.08.08 | Hash | [2019 KAKAO BLIND]오픈채팅방 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/215 | \ No newline at end of file diff --git "a/xxubin04/\355\225\264\354\213\234\353\247\265/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.py" "b/xxubin04/\355\225\264\354\213\234\353\247\265/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.py" new file mode 100644 index 0000000..3d91678 --- /dev/null +++ "b/xxubin04/\355\225\264\354\213\234\353\247\265/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.py" @@ -0,0 +1,41 @@ +def msg(act, name): + if act == "Enter": + return name+"님이 들어왔습니다." + else: # act == "Leave" + return name+"님이 나갔습니다." + + +def solution(record): + answer = [] + users = {} + + for r in record: + splitRecord = r.split() + command = splitRecord[0] + userId = splitRecord[1] + + if command == "Leave": + if userId in users: + users[userId].append((command, "")) + else: + users[userId] = [(command, "")] + else: + if userId in users: + users[userId].append((command, splitRecord[2])) + else: + users[userId] = [(command, splitRecord[2])] + + nicknames = {} + + for userId, action in users.items(): + for command, name in reversed(action): + if command == "Enter" or command == "Change": + nicknames[userId] = name + break + + for output in record: + splitOutput = output.split() + if splitOutput[0] != "Change": + answer.append(msg(splitOutput[0], nicknames[splitOutput[1]])) + + return answer \ No newline at end of file