티스토리 뷰

알고리즘/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


'알고리즘 > BOJ' 카테고리의 다른 글

[백준] 6603 로또  (0) 2018.07.05
[백준] 13701 중복 제거  (1) 2018.07.05
[백준] 9328 열쇠  (0) 2018.07.04
[백준] 5427 불  (0) 2018.07.04
[백준] 2146 다리 만들기  (4) 2018.07.04
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/04   »
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
글 보관함