티스토리 뷰

728x90
반응형

문제 링크

코드

def solution(record):
    answer = []
    myDict = {}

    # 어차피 바뀐 아이디로 출력해야되니깐 dict에 싸그리 업데이트해서 넣음
    for r in record:
        tmp = r.split()
        if len(tmp) == 3:
            action, id, nick = tmp[0], tmp[1], tmp[2]
        else:
            action, id = tmp[0], tmp[1]

        if action == "Enter" or action == "Change":
            myDict[id] = nick

    # 다시 for문 돌려 꺼내면서 Enter, Leave만 찾아 print
    for r in record:
        tmp = r.split()
        if len(tmp) == 3:
            action, id, nick = tmp[0], tmp[1], tmp[2]
        else:
            action, id = tmp[0], tmp[1]

        if action == "Enter":
            answer.append(f'{myDict[id]}님이 들어왔습니다.')
        if action == "Leave":
            answer.append(f'{myDict[id]}님이 나갔습니다.')
    return answer


solution(["Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"])
728x90
반응형
댓글
반응형
250x250
글 보관함
최근에 달린 댓글
«   2024/04   »
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
Total
Today
Yesterday
링크