쏘ing
[Python] 백준 11723 집합 본문
https://www.acmicpc.net/problem/11723
풀이 1_리스트
from collections import deque
import sys
num = int(sys.stdin.readline())
num_list = deque()
for _ in range (num):
word = sys.stdin.readline().rstrip().split()
if len(word) == 2:
x = int(word[1])
if word[0] == 'add':
if x in num_list:
pass
else:
num_list.append(x)
elif word[0] == 'remove':
if x in num_list:
num_list.remove(x)
else:
pass
elif word[0] == 'check':
if x in num_list:
print(1)
else:
print(0)
elif word[0] == 'toggle':
if x in num_list:
num_list.remove(x)
else:
num_list.append(x)
elif word[0] == 'all':
num_list = [i+1 for i in range(20)]
elif word[0] == 'empty':
num_list = []
풀이 2_집합
import sys
num = int(sys.stdin.readline())
num_list = set()
for _ in range (num):
word = sys.stdin.readline().rstrip().split()
if len(word) == 1:
if word[0] == 'all':
num_list = set([i for i in range(1, 21)])
else:
num_list = set()
else:
x = int(word[1])
word = word[0]
if word == 'add':
num_list.add(x)
elif word == 'remove':
num_list.discard(x)
elif word == 'check':
if x in num_list:
print(1)
else:
print(0)
elif word == 'toggle':
if x in num_list:
num_list.discard(x)
else:
num_list.add(x)
'알고리즘 > CLASS 3' 카테고리의 다른 글
[Python] 백준 1764 듣보잡 (0) | 2022.02.21 |
---|---|
[Python] 백준 17219 비밀번호 찾기 (0) | 2022.02.21 |
[Python] 백준 1620 나는야 포켓몬 마스터 이다솜 (0) | 2022.02.21 |
[Python] 백준 1676 팩토리얼 0의 개수 (0) | 2022.02.21 |
[Python] 백준 9375 패션왕 신해빈 (0) | 2022.02.21 |
Comments