Pagini recente » Cod sursa (job #1778207) | Cod sursa (job #2721374) | Cod sursa (job #3129942) | Cod sursa (job #359190) | Cod sursa (job #2819417)
#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);
if (op == 1)
Hash[hashul].push_back(numar);
else if (op == 2)
{
auto it = find(Hash[hashul].begin(), Hash[hashul].end(), numar);
if (it != Hash[hashul].end())
Hash[hashul].erase(it);
}
else
{
bool found = false;
for (int j = 0; j < Hash[hashul].size(); j++)
{
if (Hash[hashul][j] == numar)
{
fout << "1\n";
found = true;
}
}
if (!found)
fout << "0\n";
}
}
return 0;
}