728x90

 0. [c++] 백준  - 


https://www.acmicpc.net/problem/11723


 1. 풀이

 2. 소스코드


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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
#include<string>
#include<vector>
 
using namespace std;
 
int M;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> M;
    
    vector<bool> idx(21false);
 
    string method;
    int a;
 
    for (int i = 0; i < M; i++) {
        cin >> method;
        if (method == "add") {
            cin >> a;
            idx[a] = true;
        }
        else if (method == "remove") {
            cin >> a;
            idx[a] = false;
        }
        else if (method == "check") {
            cin >> a;
            if (idx[a])
                cout << "1\n";
            else
                cout << "0\n";
        }
        else if (method == "toggle") {
            cin >> a;
            if (idx[a])
                idx[a] = false;
            else
                idx[a] = true;
        }
        else if (method == "all") {
            for (int j = 1; j <= 20; j++)
                idx[j] = true;
        }
        else if (method == "empty") {
            for (int j = 1; j <= 20; j++)
                idx[j] = false;
        }
    }
 
    return 0;
}
cs


 3. 참고




질문이나 지적 있으시면 댓글로 남겨주세요~

도움 되셨으면 하트 꾹!


+ Recent posts