반응형
이 문제에서 연습할 수 있다.
아래 소스는 위 문제의 답안이기도 하다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int S = 0;
int M; scanf("%d", &M); while (M--) {
char a[10]; int b; scanf("%s", a);
string s = a;
if (s == "add") scanf("%d", &b), S |= (1 << (b - 1));
if (s == "check") scanf("%d", &b), printf("%d\n", S & (1 << (b - 1)) ? 1 : 0);
if (s == "remove") scanf("%d", &b), S &= ~(1 << (b - 1));
if (s == "toggle") scanf("%d", &b), S ^= (1 << (b - 1));
if (s == "all") S = 0 - 1;
if (s == "empty") S = 0;
}
return 0;
}
|
cs |
조금 까리하건 remove와 toggle인데 생각해내기 어렵진 않다.
반응형
'Programming > Algorithm' 카테고리의 다른 글
| 유니온 파인드(Union-Find), 서로소 집합(Disjoint Set) (0) | 2020.04.10 |
|---|---|
| 그래프 최장거리, 최대이득, 최다비용등 (1) | 2020.04.09 |
| 사이클 검출(Cycle Detection) (2) | 2020.03.30 |
| 플로이드 와샬 알고리즘(Floyd-Warshall Algorithm) (0) | 2020.03.28 |
| SPFA (Shortest Path Faster Algorithm) (0) | 2020.03.27 |
