Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 1차원 DP
- 2차원 dp
- 99클럽
- @BeforeAll
- @BeforeEach
- @Builder
- @Entity
- @GeneratedValue
- @GenericGenerator
- @NoargsConstructor
- @Query
- @Table
- @Transactional
- Actions
- Amazon EFS
- amazon fsx
- Android Studio
- ANSI SQL
- ApplicationEvent
- assertThat
- async/await
- AVG
- AWS
- Azure
- bind
- builder
- button
- c++
- c++ builder
- c03
Archives
- Today
- Total
기록
프로그래머스_python_오픈채팅방 본문
문제
https://programmers.co.kr/learn/courses/30/lessons/42888
코딩테스트 연습 - 오픈채팅방
오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오
programmers.co.kr
풀이
userDict에 유저의 아이디와 닉네임을 저장해둔다.
log에 유저의 행동을 uid로 저장해두었다가,
모든 기록을 읽고 난뒤 uid를 닉네임을 바꾸어 출력한다.
코드
def solution(record):
# record 읽고 기록하기
userDict = dict()
log = list()
for item in record :
cmm, *uid = item.split()
if cmm == "Enter" :
log.append([uid[0], "님이 들어왔습니다."])
userDict[uid[0]] = uid[1]
elif cmm == "Leave" :
log.append([uid[0], "님이 나갔습니다."])
else :
userDict[uid[0]] = uid[1]
# nickname 처리하기
for i in range(len(log)) :
uid, cmm = log[i]
log[i] = userDict[uid]+cmm
return log
'코딩테스트 > python' 카테고리의 다른 글
프로그래머스_python_괄호변환 (0) | 2022.02.28 |
---|---|
백준_9527_1의 개수 세기 (0) | 2022.02.26 |
프로그래머스_python_문자열압축 (0) | 2022.02.14 |
프로그래머스_python_메뉴 리뉴얼 (0) | 2022.02.09 |
프로그래머스_python_파괴되지 않은 건물 (0) | 2022.02.08 |
Comments