Algorithm/Python
[Programmers]2018 Kakao. 오픈채팅방
Pycoder
2019. 9. 29. 12:00
728x90
반응형
문제:


풀이방법:
아이디에 따른 명령어와 이름을 해시 방식으로 저장을 해줌으로써 데이터를 관리하였다. 이름을 바꾸는 경우에는 맨마지막에 해당하는 이름으로 모두 반영이 되므로 Change가 나올 때마다 덮어주는 방식으로 진행하였다. 이 외에는 명령어에 따라서 알맞게 출력해주면 된다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
def solution(record):
command=[]
name={}
for re in record:
temp=re.split()
if temp[0]=='Change':
name[temp[1]]=temp[2]
else:
if temp[0]=='Enter':
name[temp[1]]=temp[2]
command.append((temp[0],temp[1]))
answer=[]
for cmd in command:
if cmd[0]=="Enter":
answer.append("{}님이 들어왔습니다.".format(name[cmd[1]]))
else:
answer.append("{}님이 나갔습니다.".format(name[cmd[1]]))
return answer
|
cs |
문제링크:
728x90
반응형