알고리즘/BOJ

[백준] 11723 집합

세진짱 2018. 7. 5. 13:49


비트 연산의 기본 문제다

add=> or

remove => & 0

check => & 1

toggle => ^ 1

all => (1<<n) -1

empty => 0


소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std;
int n, m,x;
char s[11];
int main() {
    scanf(" %d"&m);
    for (int i = 0; i < m; i++) {
        scanf(" %s"&s);
        scanf(" %d"&x);
        if (s[0]=='a' && s[1]=='d') n |= (1 << x);
        else if (s[0== 'r') n &= ~(1 << x);
        else if (s[0== 'c'printf("%d\n", (n&(1 << x)) ==001);
        else if (s[0== 't') n ^=(1<<x);
        else if (s[0== 'a' && s[1== 'l') n = (1 << 21- 1;
        else n = 0;
    }
}
cs