Pagini recente » Cod sursa (job #316974) | Cod sursa (job #1017692) | Cod sursa (job #2681274) | Cod sursa (job #207391) | Cod sursa (job #2819418)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
// 651097 si 699401
const int mod = 651097;
int base = 97, N;
vector<int> Hash[mod + 5];
int get_hash(int modulo, int baza, int numar)
{
int hash = 0, contor = 1;
while (numar)
{
int cif = numar % 10;
hash += (cif * contor) % modulo;
contor *= baza;
contor = contor % modulo;
numar /= 10;
}
return hash;
}
int main()
{
fin >> N;
for (int i = 0; i < N; i++)
{
int op, numar, hashul;
fin >> op >> numar;
hashul = get_hash(mod, base, numar);
auto it = find(Hash[hashul].begin(), Hash[hashul].end(), numar);
if (op == 1 && it == Hash[hashul].end())
Hash[hashul].push_back(numar);
else if (op == 2 && it != Hash[hashul].end())
Hash[hashul].erase(it);
else if (op == 3)
{
if (it != Hash[hashul].end())
fout << "1\n";
else
fout << "0\n";
}
}
return 0;
}