알고리즘/[python] 백준 BOJ
[python] 백준 11723 집합
Alan_Kim
2023. 1. 18. 20:15
728x90
반응형
https://www.acmicpc.net/problem/11723
11723번: 집합
첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.
www.acmicpc.net
문제 해결
집합의 연산에 대해서 확인 할 수 있는 기본적 문제라 생략.
CODE
import sys
input = sys.stdin.readline
M = int(input())
S = set()
for _ in range(M):
command = input().split()
if command[0] == 'add':
S.add(int(command[1]))
elif command[0] == 'remove':
try:
S.remove(int(command[1]))
except:
continue
elif command[0] == 'check':
if int(command[1]) in S:
print(1)
else:
print(0)
elif command[0] == 'toggle':
if int(command[1]) in S:
S.remove(int(command[1]))
else:
S.add(int(command[1]))
elif command[0] == 'all':
S = set([i for i in range(1,21)])
else:
S = set()
728x90
반응형