코딩테스트/Python
[Python] 백준 #11723 - 집합
yo~og
2022. 7. 14. 13:37
문제
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 _ in range(n):
arr = sys.stdin.readline().strip().split()
if arr[0] == 'add':
s.add(int(arr[1]))
elif arr[0] == 'remove':
try:
s.remove(int(arr[1]))
except:
pass
elif arr[0] == 'check':
if int(arr[1]) in s: print(1)
else: print(0)
elif arr[0] == 'toggle':
if int(arr[1]) in s: s.remove(int(arr[1]))
else: s.add(int(arr[1]))
elif arr[0] == 'all':
s = {i for i in range(1,21)}
else:
s = set()