Created
August 30, 2019 16:44
-
-
Save surinoel/01e1409ca9f579a5dbf5bc4def04f509 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
int select = 0; | |
while (n--) { | |
string op; | |
int val; | |
cin >> op; | |
if (op == "add") { | |
cin >> val; | |
select |= (1 << val); | |
} | |
else if (op == "check") { | |
cin >> val; | |
if (select & (1 << val)) cout << 1 << '\n'; | |
else cout << 0 << '\n'; | |
} | |
else if (op == "remove") { | |
cin >> val; | |
select &= ~(1 << val); | |
} | |
else if (op == "toggle") { | |
cin >> val; | |
if (select & (1 << val)) { | |
select &= ~(1 << val); | |
} | |
else { | |
select |= (1 << val); | |
} | |
} | |
else if (op == "all") { | |
select = (1 << 21) - 1; | |
} | |
else if (op == "empty") { | |
select = 0; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment