Repository navigation
Expand file tree
/
Copy path0630_openchatting.py
More file actions
67 lines (55 loc) · 1.77 KB
/
Copy path0630_openchatting.py
File metadata and controls
67 lines (55 loc) · 1.77 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def solution(records):
name ={}
answer=[]
for record in reversed(records):
li = record.split(" ")
if len(li) ==2:
state = li[0]
id = li[1]
else:
state = li[0]
id = li[1]
nick = li[2]
if id not in name.keys():
name[id] = nick
if state == "Change":
name['id'] = nick
elif state == "Enter":
answer.append(f"{name[id]}님이 들어왔습니다.")
elif state =="Leave":
answer.append(f"{name[id]}님이 나갔습니다.")
return answer[::-1]
records = ["Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"]
print(solution(records))
'''
이름을 바꾸고 들어면 채팅방의 기록이 모두 바뀐 이름으로 기록된ㅏ.
나가지 않고 이름을 바꿔도 기록이 모두 바뀐 이름으로 기록된ㅏ
state id nickname
id : nickname
'''
def solution(records):
name ={}
answer=[]
for record in records:
li = record.split(" ")
if len(li) == 2:
state = li[0]
id = li[1]
nick=''
else:
state = li[0]
id = li[1]
nick = li[2]
name[id] = nick
if state !='Change':
answer.append([id, state])
for i in range(len(answer)):
if answer[i][1] =='Enter':
answer[i] = f"{name[answer[i][0]]}님이 들어왔습니다."
elif answer[i][1] == 'Leave':
answer[i] = f"{name[answer[i][0]]}님이 나갔습니다."
else:
pass
return answer
records = ["Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"]
print(solution(records))