728x90
https://www.acmicpc.net/problem/11723
11723번: 집합
첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.
www.acmicpc.net
import sys
n = int(input())
s = set()
for i in range(n):
inp = sys.stdin.readline().strip().split()
if len(inp) == 1:
if inp[0] == 'all':
s = set(range(1, 21))
else:
s = set()
continue
command, num = inp[0], int(inp[1])
if command == 'add':
s.add(num)
if command == 'remove':
s.discard(num)
if command == 'check':
print(1 if num in s else 0)
if command == 'toggle':
if num in s:
s.discard(num)
else:
s.add(num)
반응형
'전.py' 카테고리의 다른 글
[python] 백준 1764 듣보잡 (0) | 2022.02.14 |
---|---|
[python] 백준 1676 팩토리얼 0의 개수 (0) | 2022.02.14 |
[python] 백준 1541 잃어버린 괄호 (0) | 2022.02.14 |
[python] 문자열 재정렬 (0) | 2022.02.14 |
[python] 왕실의 나이트 (0) | 2022.02.14 |