https://www.acmicpc.net/problem/11723
풀이(unordered_map)
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <sstream>
using namespace std;
unordered_map<int, int> MapArray;
string StrCalculation{};
int Value;
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
freopen("input.txt", "rt", stdin);
int M{};
cin >> M;
for (int i = 0; i < M; ++i)
{
cin >> StrCalculation;
if (StrCalculation == "add")
{
cin >> Value;
MapArray[Value] = 1;
}
else if (StrCalculation == "remove")
{
cin >> Value;
MapArray[Value] = 0;
}
else if (StrCalculation == "check")
{
cin >> Value;
if (MapArray[Value])
{
cout << 1 << '\n';
}
else
{
cout << 0 << '\n';
}
}
else if (StrCalculation == "toggle")
{
cin >> Value;
if (MapArray[Value])
{
MapArray[Value] = 0;
}
else
{
MapArray[Value] = 1;
}
}
else if (StrCalculation == "all")
{
for (int j = 1; j <= 20; ++j)
{
MapArray[j] = 1;
}
}
else
{
for (int j = 1; j <= 20; ++j)
{
MapArray[j] = 0;
}
}
}
return 0;
}
풀이(bitmasking)