Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created August 30, 2019 16:44
Show Gist options
  • Save surinoel/01e1409ca9f579a5dbf5bc4def04f509 to your computer and use it in GitHub Desktop.
Save surinoel/01e1409ca9f579a5dbf5bc4def04f509 to your computer and use it in GitHub Desktop.
#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