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
| def print_message(raw_text):
if raw_text == "Enter":
raw_text = "님이 들어왔습니다."
elif raw_text == "Leave":
raw_text = "님이 나갔습니다."
return raw_text
def solution(record):
length = len(record)
status = []
user_id = []
nick_name = []
for i in range(length):
# 데이터를 역순으로 불러와 띄어쓰기로 구분
temp = record[length - 1 - i].split(" ")
status.append(temp[0])
user_id.append(temp[1])
if len(temp) == 3:
nick_name.append(temp[2])
else:
nick_name.append("")
# 가장 마지막에 등장한 user_id와 nick_name의 매치를 구한다
chk_list = []
index_num = []
for i in range(len(user_id)):
if user_id[i] not in chk_list:
chk_list.append(user_id[i])
index_num.append(i)
last_id = []
for i in range(length):
if i in index_num: # 첫 인덱스번호에 있는 데이터를 만나면
last_id.append([user_id[i], nick_name[i]]) # user_id와 nick_name 쌍을 저장
else:
for j in range(len(last_id)):
if user_id[i] == last_id[j][0]:
nick_name[i] = last_id[j][1]
answer = []
# 메시지 출력
for i in range(length):
if status[i] == "Change":
continue
else:
status[i] = print_message(status[i])
temp = nick_name[i] + status[i]
answer.append("".join(temp))
answer = print(list(reversed(answer)))
return answer
|