๋ฌธ์
https://www.acmicpc.net/problem/11723
11723๋ฒ: ์งํฉ
์ฒซ์งธ ์ค์ ์ํํด์ผ ํ๋ ์ฐ์ฐ์ ์ M (1 ≤ M ≤ 3,000,000)์ด ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ M๊ฐ์ ์ค์ ์ํํด์ผ ํ๋ ์ฐ์ฐ์ด ํ ์ค์ ํ๋์ฉ ์ฃผ์ด์ง๋ค.
www.acmicpc.net
ํ์ด
# ๋ฐฑ์ค 11723๋ฒ ๋ฌธ์ - ์งํฉ
import sys
s = set()
n = int(input())
for i in range(n):
tmp = sys.stdin.readline().strip().split()
if len(tmp) == 1: # tmp ๊ธธ์ด๊ฐ 1
if tmp[0] == 'all': # all
s = set([i for i in range(1,21)])
else: # empty
s = set()
continue
command, target = tmp[0], tmp[1]
target = int(target)
if command == 'add':
s.add(target)
elif command == 'check':
print(1 if target in s else 0)
elif command == 'remove':
s.discard(target)
elif command == 'toggle':
if target in s:
s.dicard(target)
else:
s.add(target)
์ฒ์์ ์๊ฐ์ด๊ณผ๊ฐ ๋์์ ๊ณ ๋ฏผํ ๊ฒฐ๊ณผ tmp๊ฐ 1์ผ ๊ฒฝ์ฐ๋ฅผ ๋๋์ด ์ฃผ๋ฉด ์๊ฐ์ด ์ค์ด๋ค๊ณ sys๋ก ์ ๋ ฅ์ ๋ฐ๋๋ก ํ์๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] Class3_17129๋ฒ_๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ (0) | 2022.10.28 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] Class3_1764๋ฒ_๋ฃ๋ณด์ก (0) | 2022.10.28 |
[๋ฐฑ์ค] [Python] Class3_1676๋ฒ_ํฉํ ๋ฆฌ์ผ 0์ ๊ฐ์ (0) | 2022.10.28 |
[๋ฐฑ์ค] [Python] Class2_15829๋ฒ_Hashing (0) | 2022.10.27 |
[๋ฐฑ์ค] [Python] Class2_10866๋ฒ_๋ฑ (0) | 2022.10.27 |