기억은 짧고 기록은 길다
[프로그래머스/Programmers] 오픈채팅방 - Python 본문
Link
코딩테스트 연습 - 오픈채팅방
오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오
programmers.co.kr
Solution
def solution(record):
log = []
d = {}
for i in range(len(record)):
temp = record[i].split(' ')
if temp[0] == 'Leave':
log.append([temp[1], "님이 나갔습니다."])
elif temp[0] == 'Enter':
d[temp[1]] = temp[2]
log.append([temp[1], "님이 들어왔습니다."])
elif temp[0] == 'Change':
d[temp[1]] = temp[2]
answer = []
for i in range(len(log)):
answer.append(d[log[i][0]] + log[i][1])
return answer
🔑 key point: Dictionary
Other Solution
def solution(record):
answer = []
namespace = {}
printer = {'Enter':'님이 들어왔습니다.', 'Leave':'님이 나갔습니다.'}
for r in record:
t = r.split(' ')
if t[0] in ['Enter', 'Change']:
namespace[t[1]] = t[2]
for r in record:
t = r.split(' ')
if t[0] != 'Change':
answer.append(namespace[t[1]] + printer[t[0]])
return answer
🔑 key point: Dictionary'CodingTest > programmers' 카테고리의 다른 글
| [프로그래머스/Programmers] [3차] 파일명 정렬 - Python (0) | 2021.10.09 |
|---|---|
| [프로그래머스/Programmers] 수식 최대화 - Python (0) | 2021.10.08 |
| [프로그래머스/Programmers] 영어 끝말잇기 - Python (0) | 2021.10.06 |
| [프로그래머스/Programmers] 스킬트리 - Python (0) | 2021.10.05 |
| [프로그래머스/Programmers] JadenCase 문자열 만들기 - Python (0) | 2021.10.04 |
Comments