[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ / ํŒŒ์ด์ฌ / Python / 2019 KAKAO BLIND RECRUITMENT
Algorithm/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ / ํŒŒ์ด์ฌ / Python / 2019 KAKAO BLIND RECRUITMENT

728x90
๋ฐ˜์‘ํ˜•

 

๐Ÿ’กsolutions )

๐Ÿ’ฌ userid์™€ name์„ ๋‹ด๋Š” ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ -> userid๋กœ ์œ ์ €๋“ค์„ ๊ตฌ๋ถ„ํ•˜์—ฌ name์„ ์—…๋ฐ์ดํŠธํ•ด์คŒ

๐Ÿ’ฌ results ๋ฆฌ์ŠคํŠธ์—๋Š” ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•˜๋Š” Change๋ฅผ ์ œ์™ธํ•˜๊ณ  ์ฑ„ํŒ…๋ฐฉ์„ ๋“ค์–ด์˜ค๊ฑฐ๋‚˜ ๋‚˜๊ฐ€๋Š” ๊ฒฝ์šฐ์—๋งŒ id์™€ Enter, Leave ๋ช…๋ น์–ด๋ฅผ ํŠœํ”Œ ํ˜•ํƒœ๋กœ ํ•จ๊ป˜ ๋„ฃ๋Š”๋‹ค.

๐Ÿ’ฌ results์— ๋„ฃ์–ด๋’€๋˜ ์ˆœ์„œ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š”๋ฐ ์ด๋•Œ userid๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ id_name_dict์—์„œ ํ•ด๋‹น ์œ ์ €์˜ ์ด๋ฆ„์„ ๊บผ๋‚ด์„œ ์ถœ๋ ฅํ•œ๋‹ค.

 

๐Ÿ‘จ‍๐Ÿ’ปcode )

def solution(records):
    id_name_dict = {}
    results = []
    answer = []
    for record in records:
        record_lst = record.split(' ')
        if record_lst[0] != "Leave":
            if record_lst[1] not in id_name_dict:
                    id_name_dict[record_lst[1]] = record_lst[2]
            else:
                id_name_dict[record_lst[1]] = record_lst[2]
        if record_lst[0] != "Change":
            results.append((record_lst[1], record_lst[0]))
    
    for result in results:
        if result[1] == "Enter":
            tmp = "๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."
        else:
            tmp = "๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค."
        answer.append(id_name_dict[result[0]] + "๋‹˜์ด " + tmp)
    
    return answer

 

๐Ÿ“Œdescription )

 

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

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

programmers.co.kr


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

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

"[๋‹‰๋„ค์ž„]๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."

์ฑ„ํŒ…๋ฐฉ์—์„œ ๋ˆ„๊ตฐ๊ฐ€ ๋‚˜๊ฐ€๋ฉด ๋‹ค์Œ ๋ฉ”์‹œ์ง€๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค.

"[๋‹‰๋„ค์ž„]๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค."

์ฑ„ํŒ…๋ฐฉ์—์„œ ๋‹‰๋„ค์ž„์„ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‘ ๊ฐ€์ง€์ด๋‹ค.

  • ์ฑ„ํŒ…๋ฐฉ์„ ๋‚˜๊ฐ„ ํ›„, ์ƒˆ๋กœ์šด ๋‹‰๋„ค์ž„์œผ๋กœ ๋‹ค์‹œ ๋“ค์–ด๊ฐ„๋‹ค.
  • ์ฑ„ํŒ…๋ฐฉ์—์„œ ๋‹‰๋„ค์ž„์„ ๋ณ€๊ฒฝํ•œ๋‹ค.

๋‹‰๋„ค์ž„์„ ๋ณ€๊ฒฝํ•  ๋•Œ๋Š” ๊ธฐ์กด์— ์ฑ„ํŒ…๋ฐฉ์— ์ถœ๋ ฅ๋˜์–ด ์žˆ๋˜ ๋ฉ”์‹œ์ง€์˜ ๋‹‰๋„ค์ž„๋„ ์ „๋ถ€ ๋ณ€๊ฒฝ๋œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ์ฑ„ํŒ…๋ฐฉ์— "Muzi"์™€ "Prodo"๋ผ๋Š” ๋‹‰๋„ค์ž„์„ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋žŒ์ด ์ˆœ์„œ๋Œ€๋กœ ๋“ค์–ด์˜ค๋ฉด ์ฑ„ํŒ…๋ฐฉ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฉ”์‹œ์ง€๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค.

"Muzi๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."
"Prodo๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."

์ฑ„ํŒ…๋ฐฉ์— ์žˆ๋˜ ์‚ฌ๋žŒ์ด ๋‚˜๊ฐ€๋ฉด ์ฑ„ํŒ…๋ฐฉ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚จ๋Š”๋‹ค.

"Muzi๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."
"Prodo๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."
"Muzi๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค."

Muzi๊ฐ€ ๋‚˜๊ฐ„ํ›„ ๋‹ค์‹œ ๋“ค์–ด์˜ฌ ๋•Œ, Prodo ๋ผ๋Š” ๋‹‰๋„ค์ž„์œผ๋กœ ๋“ค์–ด์˜ฌ ๊ฒฝ์šฐ ๊ธฐ์กด์— ์ฑ„ํŒ…๋ฐฉ์— ๋‚จ์•„์žˆ๋˜ Muzi๋„ Prodo๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝ๋œ๋‹ค.

"Prodo๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."
"Prodo๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."
"Prodo๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค."
"Prodo๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."

์ฑ„ํŒ…๋ฐฉ์€ ์ค‘๋ณต ๋‹‰๋„ค์ž„์„ ํ—ˆ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ˜„์žฌ ์ฑ„ํŒ…๋ฐฉ์—๋Š” Prodo๋ผ๋Š” ๋‹‰๋„ค์ž„์„ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋žŒ์ด ๋‘ ๋ช…์ด ์žˆ๋‹ค. ์ด์ œ, ์ฑ„ํŒ…๋ฐฉ์— ๋‘ ๋ฒˆ์งธ๋กœ ๋“ค์–ด์™”๋˜ Prodo๊ฐ€ Ryan์œผ๋กœ ๋‹‰๋„ค์ž„์„ ๋ณ€๊ฒฝํ•˜๋ฉด ์ฑ„ํŒ…๋ฐฉ ๋ฉ”์‹œ์ง€๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝ๋œ๋‹ค.

"Prodo๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."
"Ryan๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."
"Prodo๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค."
"Prodo๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค."

์ฑ„ํŒ…๋ฐฉ์— ๋“ค์–ด์˜ค๊ณ  ๋‚˜๊ฐ€๊ฑฐ๋‚˜, ๋‹‰๋„ค์ž„์„ ๋ณ€๊ฒฝํ•œ ๊ธฐ๋ก์ด ๋‹ด๊ธด ๋ฌธ์ž์—ด ๋ฐฐ์—ด record๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๋ชจ๋“  ๊ธฐ๋ก์ด ์ฒ˜๋ฆฌ๋œ ํ›„, ์ตœ์ข…์ ์œผ๋กœ ๋ฐฉ์„ ๊ฐœ์„คํ•œ ์‚ฌ๋žŒ์ด ๋ณด๊ฒŒ ๋˜๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ๋ฌธ์ž์—ด ๋ฐฐ์—ด ํ˜•ํƒœ๋กœ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•˜๋ผ.

์ œํ•œ์‚ฌํ•ญ

  • record๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฌธ์ž์—ด์ด ๋‹ด๊ธด ๋ฐฐ์—ด์ด๋ฉฐ, ๊ธธ์ด๋Š” 1 ์ด์ƒ 100,000 ์ดํ•˜์ด๋‹ค.
  • ๋‹ค์Œ์€ record์— ๋‹ด๊ธด ๋ฌธ์ž์—ด์— ๋Œ€ํ•œ ์„ค๋ช…์ด๋‹ค.
    • ๋ชจ๋“  ์œ ์ €๋Š” [์œ ์ € ์•„์ด๋””]๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค.
    • [์œ ์ € ์•„์ด๋””] ์‚ฌ์šฉ์ž๊ฐ€ [๋‹‰๋„ค์ž„]์œผ๋กœ ์ฑ„ํŒ…๋ฐฉ์— ์ž…์žฅ - "Enter [์œ ์ € ์•„์ด๋””] [๋‹‰๋„ค์ž„]" (ex. "Enter uid1234 Muzi")
    • [์œ ์ € ์•„์ด๋””] ์‚ฌ์šฉ์ž๊ฐ€ ์ฑ„ํŒ…๋ฐฉ์—์„œ ํ‡ด์žฅ - "Leave [์œ ์ € ์•„์ด๋””]" (ex. "Leave uid1234")
    • [์œ ์ € ์•„์ด๋””] ์‚ฌ์šฉ์ž๊ฐ€ ๋‹‰๋„ค์ž„์„ [๋‹‰๋„ค์ž„]์œผ๋กœ ๋ณ€๊ฒฝ - "Change [์œ ์ € ์•„์ด๋””] [๋‹‰๋„ค์ž„]" (ex. "Change uid1234 Muzi")
    • ์ฒซ ๋‹จ์–ด๋Š” Enter, Leave, Change ์ค‘ ํ•˜๋‚˜์ด๋‹ค.
    • ๊ฐ ๋‹จ์–ด๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์œผ๋ฉฐ, ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž, ์†Œ๋ฌธ์ž, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ์žˆ๋‹ค.
    • ์œ ์ € ์•„์ด๋””์™€ ๋‹‰๋„ค์ž„์€ ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž, ์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ณ„ํ•œ๋‹ค.
    • ์œ ์ € ์•„์ด๋””์™€ ๋‹‰๋„ค์ž„์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 10 ์ดํ•˜์ด๋‹ค.
    • ์ฑ„ํŒ…๋ฐฉ์—์„œ ๋‚˜๊ฐ„ ์œ ์ €๊ฐ€ ๋‹‰๋„ค์ž„์„ ๋ณ€๊ฒฝํ•˜๋Š” ๋“ฑ ์ž˜๋ชป ๋œ ์ž…๋ ฅ์€ ์ฃผ์–ด์ง€์ง€ ์•Š๋Š”๋‹ค.




๋ฐ˜์‘ํ˜•