๐Ÿ“ Coding Test Study/Algorithm Problem

[C++][Baekjoon][๋น„ํŠธ๋งˆ์Šคํฌ] 11723๋ฒˆ ์ง‘ํ•ฉ

ibelieveinme 2022. 5. 8. 11:07
728x90

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

 

11723๋ฒˆ: ์ง‘ํ•ฉ

์ฒซ์งธ ์ค„์— ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์—ฐ์‚ฐ์˜ ์ˆ˜ M (1 ≤ M ≤ 3,000,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์— ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์—ฐ์‚ฐ์ด ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

#include <string>
#include <iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int calculationNum, bit = 0, num; // bit ์ดˆ๊ธฐํ™” ํ•„์ˆ˜
    string calculationString;

    cin >> calculationNum;
    for (int i = 0; i < calculationNum; i++) {
        cin >> calculationString;
        if (calculationString == "add") {
            cin >> num;
            bit |= (1 << num);
        }
        else if (calculationString == "remove") {
            cin >> num;
            bit &= ~(1 << num);
        }
        else if (calculationString == "check") {
            cin >> num;
            if (bit & (1 << num)) cout << 1 << "\n";
            else cout << 0 << "\n";
        }
        else if (calculationString == "toggle") {
            cin >> num;
            bit ^= (1 << num);
        }
        else if (calculationString == "all") {
            bit = (1 << 21) - 1;
        }
        else if (calculationString == "empty") {
            bit = 0;
        }
    }
    return 0;
}
728x90