Published 2021. 2. 20. 20:13
 

11723번: 집합

첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.

www.acmicpc.net

#include <cstdio>
#include <cstring>
using namespace std;
char b[111];
int main() {
    int n = 20;
    int m;
    scanf("%d",&m);
    int s = 0;
    int x;
    while (m--) {
        scanf("%s",b);
        if (!strcmp(b,"add")) {
            scanf("%d",&x); x--;
            s = (s | (1 << x));
        } else if (!strcmp(b,"remove")) {
            scanf("%d",&x); x--;
            s = (s & ~(1 << x));
        } else if (!strcmp(b,"check")) {
            scanf("%d",&x); x--;
            int res = (s & (1 << x));
            if (res) {
                puts("1");
            } else {
                puts("0");
            }
        } else if (!strcmp(b,"toggle")) {
            scanf("%d",&x); x--;
            s = (s ^ (1 << x));
        } else if (!strcmp(b,"all")) {
            s = (1<<n)-1;
        } else if (!strcmp(b,"empty")) {
            s = 0;
        }
    }
    return 0;
}

'Problem set' 카테고리의 다른 글

[백준] 14391 종이 조각  (0) 2021.02.20
[백준] 1182 부분수열의 합  (0) 2021.02.20
[백준] 1248 맞춰봐  (0) 2021.02.20
[백준] 2529 부등호  (0) 2021.02.20
[백준] 15661 링크와 스타트  (0) 2021.02.20
복사했습니다!