Study/알고리즘
[2019 카카오 신입 공채 1차 코딩 테스트] 1. 오픈채팅방 - python
ChocoDrogba
2019. 3. 13. 20:46
파이썬의 딕셔너러를 이용하여 해결했다. 구현만 하면 되는 문제인데 딕셔너리를 효율적으로 사용하지 않으면 시간초과가 나올수도 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | def solution(record): answer = [] buffer = [] chatroom = dict() for i in record: tmp = i.split() op = tmp[0] uid = tmp[1] if op == "Enter": nic = tmp[2] chatroom[uid] = nic buffer.append([uid, "님이 들어왔습니다."]) elif op == "Leave": buffer.append([uid, "님이 나갔습니다."]) else: nic = tmp[2] chatroom[uid] = nic for i in buffer: answer.append(chatroom[i[0]] + i[1]) return answer | cs |