오픈채팅방
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
- 내 풀이
- 각각의 문자열이 split했을때 같은 길이 값으로 나오는지를 고려해야함.
- Leave일때는 값이 2개나오는 경우를 확인못해서 시간소모가 있었음
def solution(record):
result = []
answer=[]
dict={}
for rc in record:
rc_lst=list(rc.split(" "))
behavior=rc_lst[0]
user_id=rc_lst[1]
if len(rc_lst)==3:
name=rc_lst[2]
if user_id not in dict:
dict[user_id]=""
if behavior=='Enter':
dict[user_id]=name
result.append((0,user_id))
elif behavior=='Leave':
result.append((1,user_id))
elif behavior=='Change':
dict[user_id]=name
for rs in result:
inout, user_id=rs
if inout==0:
answer.append(dict[user_id]+"님이 들어왔습니다.")
else:
answer.append(dict[user_id]+"님이 나갔습니다.")
return answer
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
| [프로그래머스][Counter] 롤케이크 자르기 (0) | 2024.11.17 |
|---|---|
| [프로그래머스] [DP] 숫자 변환하기 (1) | 2024.11.16 |
| [프로그래머스][DP] 등굣길 (0) | 2024.11.01 |
| [프로그래머스][백트래킹] 단어 변환 (0) | 2024.11.01 |
| [프로그래머스][Heap] 야근 지수 (0) | 2024.11.01 |