-
Notifications
You must be signed in to change notification settings - Fork 0
/
back.py
115 lines (82 loc) · 2.14 KB
/
back.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import sys
x =0
S=set()
class Zip():
def __init__(self):
self.x=x
self.s=S
def loof(self):
loof_nums = sys.stdin.readline()
loof_num = int(loof_nums)
while loof_num>=0 :
insert = sys.stdin.readline()
insert_def = insert.split()
def_name = insert_def[0]
if len(insert_def) >= 2:
x=insert_def[1]
if def_name == "add" :
self.add_x(x)
elif def_name == "remove" :
self.remove_x(x)
elif def_name == "check" :
self.check_x(x)
elif def_name == "toggle" :
self.toggle_x(x)
elif def_name == "all" :
self.all()
print(self.s)
elif def_name == "empty" :
self.empty()
loof_num = loof_num - 1
def add_x(self, x):
match = False
for i in self.s:
if i == int(x):
match = True
else :
match = False
if match == False:
self.s.add(int(x))
else: pass
def remove_x(self, x):
match = False
for i in self.s:
if i == int(x):
match = True
break
else:
match = False
if match == True:
self.s.remove(int(x))
def check_x(self, x):
match = False
for i in self.s:
if i == int(x):
match = True
break
else:
match = False
if match ==True:
print(1)
else:
print(0)
def toggle_x(self, x):
match = False
for i in self.s:
if i == int(x):
match = True
break
else:
match = False
if match == True:
self.s.remove(int(x))
else:
self.s.add(int(x))
def all(self):
self.s = set()
for i in range(1,21):
self.s.add(i)
def empty(self):
self.s=set()
zip = Zip()
zip.loof()