๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • What would life be If we had no courage to attemp anything?
Problem Solving/PROGRAMMERS

[python]ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ

by DevIseo 2022. 7. 29.

[python]ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ

https://school.programmers.co.kr/learn/courses/30/lessons/42888

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

def solution(record):
    answer=[]
    actions = []
    userDb= {}
    for r in record:
    	#๋„์–ด์“ฐ๊ธฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆ„๊ธฐ
        temp = r.split()
        state,userId = temp[0],temp[1]
        #๋‹‰๋„ค์ž„ ๋ฐ”๋€” ๋•Œ์™€ ๋‹ค์‹œ ๋“ค์–ด์˜ฌ ๋•Œ ์ด๋ฆ„ ๋ฐ”๋€Œ๊ฒŒ dictionary ์‚ฌ์šฉ
        if state in ('Enter','Change'):
            nickname = temp[2]
            userDb[userId] = nickname
        actions.append((state,userId))
    
    for a in actions:
        state,nick = a[0],a[1]
        if state == 'Enter':
            answer.append(f'{userDb[nick]}๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.')
        elif state == 'Leave':
            answer.append(f'{userDb[nick]}๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.')
    return answer

๋Œ“๊ธ€