ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Programmers] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ with Python
    PS 2021. 11. 21. 18:18
    728x90
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ“Œ Programmers - [์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ]

    ๐Ÿ’ก ์กฐ๊ฑด

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

    2. record๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฌธ์ž์—ด์ด ๋‹ด๊ธด ๋ฐฐ์—ด์ด๋ฉฐ, ๊ธธ์ด๋Š” 1 ์ด์ƒ 100,000 ์ดํ•˜

    3. ๋ชจ๋“  ์œ ์ €๋Š” ์œ ์ € ์•„์ด๋””๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค.
      ์œ ์ € ์•„์ด๋”” ์‚ฌ์šฉ์ž๊ฐ€ ๋‹‰๋„ค์ž„์œผ๋กœ ์ฑ„ํŒ…๋ฐฉ์— ์ž…์žฅ - "Enter ์œ ์ € ์•„์ด๋”” ๋‹‰๋„ค์ž„" (ex. "Enter uid1234 Muzi")

    4. ๊ตฌํ˜„ ์œ ํ˜•์˜ ๋ฌธ์ œ

    ๐Ÿ–ฅ ์†Œ์Šค ์ฝ”๋“œ

    def solution(record):
        result = []
        answer = []
        status = ["๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.", "๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค."]
        id_code = {}
    
        for r in record:
            l = r.split()
    
            if l[0] == 'Enter':
                id_code[l[1]] = l[2]
                result.append([0, l[1]])
    
            elif l[0] == 'Leave':
                result.append([1, l[1]])
    
            else:
                id_code[l[1]] = l[2]
    
        for s, uid in result:
            answer.append(id_code[uid] + status[s])
    
        return answer

    ๐Ÿ”– ์˜ˆ์ œ ๋ฐ ์‹คํ–‰๊ฒฐ๊ณผ

    ์˜ˆ์ œ

    record = ["Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"]

    ์‹คํ–‰๊ฒฐ๊ณผ

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

    โŒจ๏ธ ๋ฌธ์ œ ํ’€์ด

    1. ๋ฌธ์ œ์˜ ์ •๋‹ต์„ ์ถœ๋ ฅํ•  ๋ฐฐ์—ด answer, (์ƒํƒœ, uid) ์ •๋ณด๋ฅผ ์ €์žฅํ•  ๋ฐฐ์—ด result,
      ์ž…์žฅ๊ณผ ํ‡ด์žฅ์˜ ๋ฌธ๊ตฌ๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด status, (uid, ๋‹‰๋„ค์ž„)์ด ๋‹ด๊ฒจ์žˆ๋Š” ๋”•์…”๋„ˆ๋ฆฌ id_code ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
    1. record๋ฅผ ์ˆœํšŒํ•˜๋ฉด์„œ ๊ฐ€์žฅ ์ฒซ ์ •๋ณด๊ฐ€ Enter ์ผ ๊ฒฝ์šฐ, id_code ๋”•์…”๋„ˆ๋ฆฌ์— uid: ๋‹‰๋„ค์ž„ ํ˜•์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•œ๋‹ค.
      result์— (์ƒํƒœ์ฝ”๋“œ, uid) ๋ฅผ ์ €์žฅํ•œ๋‹ค.

    2. ์ฒซ ์ •๋ณด๊ฐ€ Leave ์ผ ๊ฒฝ์šฐ, result์— (์ƒํƒœ์ฝ”๋“œ, uid) ๋ฅผ ์ €์žฅํ•œ๋‹ค.

    1. ์ฒซ ์ •๋ณด๊ฐ€ Change ์ผ ๊ฒฝ์šฐ, id_code์˜ uid ์— ํ•ด๋‹นํ•˜๋Š” ๋‹‰๋„ค์ž„์„ ๋ณ€๊ฒฝํ•œ๋‹ค.
    1. result ๋ฐฐ์—ด์„ ์ˆœํšŒํ•˜๋ฉด์„œ id_code ๋”•์…”๋„ˆ๋ฆฌ์˜ uid์— ํ•ด๋‹นํ•˜๋Š” ๋‹‰๋„ค์ž„๊ณผ ์Šคํ…Œ์ดํ„ฐ์Šค ๋ฒˆํ˜ธ๋ฅผ ํ•จ๊ป˜ answer ๋ฐฐ์—ด์— ์ €์žฅํ•œ๋‹ค.
    1. answer๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

    ๐Ÿ’พ ๋Š๋‚€์ 

    1. uid ๋ฒˆํ˜ธ์— ๋”ฐ๋ฅธ ์ƒํƒœ์™€, ๋‹‰๋„ค์ž„์„ ๋ณ€๊ฒฝํ•˜์—ฌ ๊ทธ์— ๋งž๊ฒŒ ์ถœ๋ ฅํ•˜๋Š” ๊ตฌํ˜„๋ฌธ์ œ์˜€๋‹ค.
    2. ์ƒํƒœ๋ฅผ ์ €์žฅ์„ ์–ด๋–ป๊ฒŒ ํ• ์ง€์— ๋Œ€ํ•ด์„œ ๊ณ ๋ฏผ์„ ํ•˜๋‹ค๊ฐ€ ์˜ค๋ž˜๊ฑธ๋ ธ์—ˆ๋Š”๋ฐ, ์ง์ ‘ ๊ตฌํ˜„์„ ํ•˜๊ณ  ๋ณด๋‹ˆ ์งง๊ณ  ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์˜€๋‹ค.
    3. ๊ตฌํ˜„ ์—ฐ์Šต์„ ๋” ์—ด์‹ฌํžˆ ํ•ด์•ผํ•˜๊ฒ ๋‹ค.
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.