11723번 - 집합
import sys
input = sys.stdin.readline
a = set()
for i in range(int(input().rstrip())):
b = str(input().rstrip())
if "add" in b:
c = list(b.split(" "))
a.add(c[1])
elif "remove" in b:
a.discard(c[1])
elif "check" in b:
if c[1] in a:
print(1)
else:
print(0)
elif "toggle" in b:
a.remove(c[1])
elif b == "all":
a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
elif b == "empty":
all로 집합에 int만이 있는 상태에서
check는 str로 됩니다.
댓글을 작성하려면 로그인해야 합니다.
smilingwon20 2년 전
import sys
input = sys.stdin.readline
a = set()
for i in range(int(input().rstrip())):
b = str(input().rstrip())
if "add" in b:
c = list(b.split(" "))
a.add(c[1])
elif "remove" in b:
c = list(b.split(" "))
a.discard(c[1])
elif "check" in b:
c = list(b.split(" "))
if c[1] in a:
print(1)
else:
print(0)
elif "toggle" in b:
c = list(b.split(" "))
if c[1] in a:
a.remove(c[1])
else:
a.add(c[1])
elif b == "all":
a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
elif b == "empty":
a = set()