Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ (์นด์นด์˜ค, level.2)

๊ฐ์ž ๐Ÿฅ” 2021. 9. 16. 13:50
๋ฐ˜์‘ํ˜•

 

๋ฌธ์ œ ๋งํฌ

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

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ

์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ ์นด์นด์˜คํ†ก ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ์—์„œ๋Š” ์นœ๊ตฌ๊ฐ€ ์•„๋‹Œ ์‚ฌ๋žŒ๋“ค๊ณผ ๋Œ€ํ™”๋ฅผ ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ๋ณธ๋ž˜ ๋‹‰๋„ค์ž„์ด ์•„๋‹Œ ๊ฐ€์ƒ์˜ ๋‹‰๋„ค์ž„์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฑ„ํŒ…๋ฐฉ์— ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋‹ค. ์‹ ์ž…์‚ฌ์›์ธ ๊น€ํฌ๋ฃจ๋Š” ์นด์นด์˜คํ†ก ์˜ค

programmers.co.kr

 

๋‚˜์˜ํ’€์ด

  1. ๋”•์…”๋„ˆ๋ฆฌ์˜ key๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ value๋ฅผ ๋„ฃ์–ด์ฃผ๋ฉด, ๊ฐ€์žฅ ์ตœ๊ทผ์˜ value๋ฅผ ์ €์žฅํ•œ๋‹ค๋Š” ํŠน์ง•์„ ์ด์šฉ
  2. ์‚ฌ์šฉ์ž๋Š” Enterํ•  ๋•Œ, changeํ•  ๋•Œ ๋‹‰๋„ค์ž„์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ์ด ๋‘๊ฐ€์ง€์˜ ๊ฒฝ์šฐ์— ํ•œํ•ด์„œ dic์— userid(KEY) ๊ธฐ์ค€์œผ๋กœ Nickname(VALUE)๋ฅผ ์ €์žฅํ•ด์คŒ
def solution(record):
    # ์šฐ์„  split์œผ๋กœ ๋‹ค ๋‚˜๋ˆ ์„œ ๋ฆฌ์ŠคํŠธ๋กœ ์ €์žฅ
    records = []
    result = []
    for i in range(len(record)):
        records.append(record[i].split())
    # ๋‹‰๋„ค์ž„ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ ๋ฐฉ๋ฒ•์ด enter, change๋‹ˆ๊นŒ ๋‘๊ฐœ๋ฅผ ์ด์šฉํ•ด์„œ dic์ž‘์„ฑ
    dic = {}
    for r in records: # ์•„์ด๋””๋ž‘ ๋‹‰๋„ค์ž„์„ ์—…๋ฐ์ดํŠธ (๋‹‰๋„ค์ž„์€ ๋ฐ”๋€Œ๋ฉด ๊ฐ€์žฅ ์ตœ์‹ ๊ฑธ๋กœ ์—…๋ฐ์ดํŠธ)
        if r[0] in ['Enter', 'Change']:
            dic[r[1]] = r[2]

    for r in records:
        nickname = dic[r[1]]
        if r[0] == 'Enter':
            answer = nickname+'๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.'
        elif r[0] == 'Leave':
            answer = nickname+'๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.'
        else: continue
        result.append(answer)

    return result

 

๋‹ค๋ฅธ์‚ฌ๋žŒ ํ’€์ด

https://programmers.co.kr/learn/courses/30/lessons/42888/solution_groups?language=python3&type=all 

 

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

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

programmers.co.kr

์•„ ์ด๋ ‡๊ฒŒ leave, enter๋„ ๋”•์…”๋„ˆ๋ฆฌํ˜•์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋” ๋นจ๋ผ์งˆ์ˆ˜๋„ ์žˆ๊ฒŸ๋‹ค. ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ–ˆ๋”ฐ๋Š” ํ’€์ด๊ฐ€ ๊ฐ€์žฅ ์ข‹์•„์š”๋ฅผ ๋งŽ์ด ๋ฐ›์•˜๋Š”๋ฐ, ๋‚˜๋„ ๊ทธ ์•„์ด๋””์–ด๋ฅผ ๋– ์˜ฌ๋ ธ์œผ๋‹ˆ ์กฐ๊ธˆ ๋‚˜๋„ ์„ฑ์žฅํ–ˆ๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ๊ฒŸ์ง€? ํžˆํžˆ

์นด์นด์˜ค๋ฌธ์ œ ์ •๋ณต ๊ฐ€์ฆˆ์•„์•„์•„์•„ 

 

๋ฐ˜์‘ํ˜•