Coding - Algo/python
[백준] 11723번:집합 (python 파이썬)
jainn
2021. 3. 15. 01:48
728x90
문제
11723번: 집합
첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.
www.acmicpc.net
풀이
그냥 문제에서 하라는대로 해주면 된다 ,, 쉽따 ..
소스코드
import sys
input = sys.stdin.readline
def add(x):
if x not in arr:
arr.append(x)
def remove(x):
if x in arr:
index = arr.index(x)
arr.pop(index)
def check(x):
if x in arr:
print("1")
else:
print("0")
def toggle(x):
if x in arr:
index = arr.index(x)
arr.pop(index)
else:
add(x)
def all():
global arr
arr = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20']
def empty():
global arr
arr = []
m = int(input())
arr = []
for _ in range(m):
s = input().strip()
if s == 'all':
all()
continue
elif s == 'empty':
empty()
continue
s = s.split()
if s[0] == 'add':
add(s[1])
elif s[0] == 'remove':
remove(s[1])
elif s[0] == 'check':
check(s[1])
elif s[0] == 'toggle':
toggle(s[1])
반응형