[BOJ]๋ฐฑ์ค€#4649 Silver 5 Tanning Salon๐ŸŒž๐Ÿ™†(Python, ํŒŒ์ด์ฌ)

์ž„์ค€์„ฑยท2022๋…„ 9์›” 23์ผ
0

๋ฐฑ์ค€ Algorithm

๋ชฉ๋ก ๋ณด๊ธฐ
55/59
post-thumbnail

๋ฐฑ์ค€ 4649๋ฒˆ
https://www.acmicpc.net/problem/4649

๋ฌธ์ œ



ํ›„๊ธฐ

โฐ ํ’€์ด์‹œ๊ฐ„ 20๋ถ„ ++โฐ

๋งžํžŒ ์‚ฌ๋žŒ์ด ๋งŽ์ง€ ์•Š์€ ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ ์œ„ํ•ด ํ’€์€ ์‚ฌ๋žŒ์ด ์ ์€ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์„œ

์ฐพ์€ ๋ฌธ์ œ์˜ 11๋ฒˆ์งธ๋‹ค.

๋ฌธ์ œ๋Š” ๋ฌธ์ž์—ด์„ ๋ฐ›์€ ๋‹ค์Œ ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์•ŒํŒŒ๋ฒณ์ด๋ฉด Dictionary ์•ˆ์— ๋„ฃ๊ณ ,

๊ฐ™์€ ์•ŒํŒŒ๋ฒณ์ด ๋‹ค์‹œ ๋“ฑ์žฅํ•˜๋ฉด Dictionary์—์„œ ์ œ๊ฑฐํ•œ๋‹ค.

๋งŒ์•ฝ ํƒœ๋‹ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ์žฅ์†Œ๊ฐ€ ๊ฝ‰์ฐจ๋ฉด(Dictionary์˜ ๊ธธ์ด๊ฐ€ ๊ทธ๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜๊ฐ™์œผ๋ฉด )

cnt ๊ฐ’์„ ํ•˜๋‚˜ ์ฆ๊ฐ€์‹œ์ผœ์„œ ํƒœ๋‹์„ ๋ฐ›์ง€ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ์ˆ˜๋ฅผ ์„ผ๋‹ค.

์ตœ์ข…์ ์œผ๋กœ cnt์˜ ๊ฐ’์ด 0์ด๋ฉด

All customers tanned successfully๋ฅผ ์ถœ๋ ฅํ•˜๊ณ 

๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด cnt์˜ ๊ฐ’์„ ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ๋˜๋Š” ๋ฌธ์ œ๋‹ค.

import sys
input= sys.stdin.readline

while True:
    li = list(map(str,input().rstrip().split()))
    li_dict = dict()
    cnt = 0 #ํƒœ๋‹์„ ๋ฐ›์ง€ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ์ˆ˜
    if len(li)==1 and li[0] == "0": #์ž…๋ ฅ์ด 0์ด๋ฉด ์ข…๋ฃŒ๋œ๋‹ค.
        break
    num = int(li[0])
    if len(li) != 1:
        li= li[1]
    
    for i in li:
        if i not in li_dict.keys() and len(li_dict) < num: #ํƒœ๋‹์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์œผ๋ฉด
            li_dict[i] = 1
        elif i in li_dict.keys(): #ํƒœ๋‹์ด ๋๋‚œ ์‚ฌ๋žŒ์€ ์ œ๊ฑฐ๋œ๋‹ค.
            del li_dict[i]
        elif i not in li_dict.keys() and len(li_dict) >=num: #ํƒœ๋‹ ์ž๋ฆฌ๊ฐ€ ์—†์œผ๋ฉด
            cnt += 1
    if cnt == 0: #๋ชป๋ฐ›์€ ์‚ฌ๋žŒ์ด ์—†์œผ๋ฉด 
        print("All customers tanned successfully.")
    else:
        print("{} customer(s) walked away.".format(cnt//2))
profile
์•„๋ฌด๋ตํฌ ์žˆ์ด

0๊ฐœ์˜ ๋Œ“๊ธ€