Skip to content

Commit 88160cd

Browse files
committed
[BOJ] #11723. 집합 / 실버5 / 38분(성공)
1 parent 7230823 commit 88160cd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
m = int(input()) # 수행해야 하는 연산의 수
5+
s = 0 # 비어있는 초기 공집합 S
6+
for _ in range(m):
7+
command = list(map(str, input().strip().split())) # 수행해야 하는 연산 -> all과 empty가 있으므로 리스트로 저장
8+
# 따라서 command[0]: 연산내용 command[1]: 요소
9+
if command[0] == 'add': # 원소 추가 (or)
10+
s |= (1 << int(command[1]))
11+
elif command[0] == 'remove': # 원소 삭제 (not + and)
12+
s &= ~(1 << int(command[1]))
13+
elif command[0] == 'check': # 원소 체크
14+
if s & (1<< int(command[1])):
15+
print(1)
16+
else:
17+
print(0)
18+
elif command[0] == 'toggle': # 원소 토글 (xor)
19+
s ^= (1 << int(command[1]))
20+
elif command[0] == 'all': # 원소 채우기
21+
s = (1 << 21) - 1
22+
elif command[0] == 'empty': #원소 비우기
23+
s = 0

0 commit comments

Comments
 (0)