[Python] BOJ 11723번. 집합

11723번. 집합

문제 링크

풀이 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 11723번. 집합


import sys
input = sys.stdin.readline


def add(s, x):
    if x not in s:
        s.append(x)


def remove(s, x):
    if x in s:
        s.remove(x)


def check(s, x):
    if x in s:
        return 1
    else:
        return 0


def toggle(s, x):
    if x in s:
        s.remove(x)
    else:
        s.append(x)


def all(s):
    s = [i for i in range(1, 21)]
    return s


def empty(s):
    s = []
    return s


s = []

a = []
for i in range(int(input())):
    ip = input().rstrip()
    if ip == 'all':
        s = all(s)
    elif ip == 'empty':
        s = empty(s)
    else:
        c, x = ip.split()
        x = int(x)
        if c == 'add':
            add(s, x)
        elif c == 'remove':
            remove(s, x)
        elif c == 'check':
            print(check(s, x))
        elif c == 'toggle':
            toggle(s, x)

# print(a)

비고