일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- kaggle
- Python Implementation
- Substring with Concatenation of All Words
- shiba
- Class
- attribute
- 컴퓨터의 구조
- data science
- concurrency
- 파이썬
- t1
- 운영체제
- LeetCode
- DWG
- Decorator
- 715. Range Module
- 315. Count of Smaller Numbers After Self
- 밴픽
- Python Code
- 시바견
- Convert Sorted List to Binary Search Tree
- Python
- 프로그래머스
- 109. Convert Sorted List to Binary Search Tree
- Generator
- 30. Substring with Concatenation of All Words
- 43. Multiply Strings
- Regular Expression
- iterator
- Protocol
Archives
- Today
- Total
Scribbling
프로그래머스: 오픈채팅방 본문
2019 카카오 코딩 테스트 기출 문제라고 한다.
단순 구현문제다.
from collections import defaultdict
def solution(record):
results = []
record_dict = defaultdict(list)
nickname_dict = {}
for rec in record:
rec = rec.split(' ')
if rec[0] == 'Enter':
user_id, nickname = rec[1], rec[2]
results.append(nickname + "님이 들어왔습니다.")
record_dict[user_id].append(len(results) - 1)
if user_id not in nickname_dict:
nickname_dict[user_id] = nickname
else:
if nickname_dict[user_id] != nickname:
nickname_dict[user_id] = nickname
for idx in record_dict[user_id]:
results[idx] = nickname + "님" + results[idx].split('님')[1]
elif rec[0] == 'Leave':
user_id = rec[1]
nickname = nickname_dict[user_id]
results.append(nickname + "님이 나갔습니다.")
record_dict[user_id].append(len(results) - 1)
else:
user_id, nickname = rec[1], rec[2]
nickname_dict[user_id] = nickname
for idx in record_dict[user_id]:
results[idx] = nickname + "님" + results[idx].split('님')[1]
return results
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 130. Surrounded Regions (0) | 2021.11.10 |
---|---|
LeetCode: 129. Sum Root to Leaf Numbers (0) | 2021.11.10 |
LeetCode: 128. Longest Consecutive Sequence (0) | 2021.11.08 |
프로그래머스: 방의 개수 (0) | 2021.11.08 |
LeetCode: 127. Word Ladder (0) | 2021.11.07 |