Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- dict
- 힙
- 브루트포스
- 그리디
- DP
- level3
- level1
- 가상메모리
- BFS
- dfs
- 재귀
- 가상메모리 관리
- N과M
- 운영체제
- 백준
- level0
- 다이나믹 프로그래밍
- level2
- MYSQL
- 파이썬
- programmers
- 스택
- BOJ
- 구현
- python
- 프로그래머스
- 다익스트라
- 딕셔너리
- 수학
- 코딩테스트
Archives
- Today
- Total
동캄의 코딩도장
백준 11723 [집합] 파이썬 본문
https://www.acmicpc.net/problem/11723
11723번: 집합
첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.
www.acmicpc.net
# 백준 11723 집합
import sys
input=sys.stdin.readline
M=int(input())
S=[]
for _ in range(M):
cmd=list(map(str,input().split()))
if len(cmd)==2:
command,num=cmd[0],cmd[1] #명령 + 숫자 인 경우
num=int(num)
else:
command=cmd[0] #명령만 있는 경우
if command=='add':
if not S.count(num):
S.append(num)
elif command=='remove':
if S.count(num):
S.remove(num)
elif command=='check':
if S.count(num):
print(1)
else:
print(0)
elif command=='toggle':
if S.count(num):
S.remove(num)
else:
S.append(num)
elif command=='all':
S=[i for i in range(1,21)]
elif command=='empty':
S=[]
명령어를 받아서, 각 경우에 대해 분류하고 명령대로 구현되도록 코드를 만든다.
'코테 > BOJ' 카테고리의 다른 글
백준 1620 [나는야 포켓몬 마스터 이다솜] 파이썬 (0) | 2023.03.20 |
---|---|
백준 17219 [비밀번호 찾기] 파이썬 (0) | 2023.03.20 |
백준 18111 [마인크래프트] 파이썬 (0) | 2023.03.20 |
백준 1654 [랜선 자르기] 파이썬 (0) | 2023.03.19 |
백준 6588 [골드바흐의 추측] 파이썬 (0) | 2022.10.11 |