ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค [lv2] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ ํŒŒ์ด์ฌ

2021. 4. 25. 14:55ใ†๐Ÿ”ฑ Algorithm/Else

 

 

์ ‘๊ทผ

- ์•„๋ž˜์ฒ˜๋Ÿผ set() ํ˜•์‹์œผ๋กœ ์ €์žฅํ–ˆ๋‹ค. 


(์•„์ด๋””, ์ด๋ฆ„, ๋ฉ”์‹œ์ง€)
(uid1234, Muzi, ๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.)
(uid4567, Prodo, ๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.)
(uid4567, -, ๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.)
(uid4567, Prodo, ๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.)
(uid4567, Ryan, -)

- Enter, Leave์˜ ๊ฒฝ์šฐ๋งŒ ๊ฒฐ๊ณผ๊ฐ’์— ๋ฐ˜์˜๋œ๋‹ค -> "Change"๋Š” ๋ถ„๊ธฐ ์ฒ˜๋ฆฌ

 

ํฌ์ธํŠธ

1. ์ค‘๊ฐ„์— ์ด๋ฆ„์ด ๋ฐ”๋€Œ๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ณ ๋ คํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ค‘์š”ํ•œ ํฌ์ธํŠธ๋‹ค.
2. ์ด๋ฆ„์€ ๋ฐ”๋€” ์ˆ˜ ์žˆ์ง€๋งŒ, uid๋Š” ๊ณ ์ •๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์„ key๋กœ, ๋ณ€ํ•˜๋Š” ์ด๋ฆ„์„ value๋กœ ์žก์•˜๋‹ค.
(๋”•์…”๋„ˆ๋ฆฌ ์„ฑ์งˆ์— ์˜ํ•ด, ์ฑ„ํŒ…๋ฐฉ์„ ๋‚˜๊ฐ„ ํ›„ ์ด๋ฆ„์ด ๋ณ€ํ•˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ณง๋ฐ”๋กœ ์ปค๋ฒ„ํ•  ์ˆ˜ ์žˆ๋‹ค. uid๋Š” ๋™์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ณ€๊ฒฝ๋œ ์ด๋ฆ„๋งŒ update ๋œ๋‹ค.)
3. ์ด๋ฆ„์ด ๋ฐ”๋€” ๋•Œ์˜ ๋ฉ”์‹œ์ง€๋Š” ์ถœ๋ ฅํ•˜์ง€ ์•Š๋Š”๋‹ค.

 

 

def solution(record):
    answer, tmp = list(), list()
    id_name = {"Enter": "๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.",
               "Leave": "๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค."}
    temp = [string.split(' ') for string in record]
    for i in temp:
        if i[0] != 'Leave':
            id_name[i[1]] = i[2]
        if i[0] == "Enter" or i[0] == "Leave":
            tmp.append('{},{}'.format(i[1], i[0]))
    for i in tmp:
        a, b = i.split(',')
        answer.append('{}{}'.format(id_name[a], id_name[b]))

    return answer