Pagini recente » Cod sursa (job #1280437) | Rating Perhaita Daniel (danyy13) | Cod sursa (job #2087168) | Cod sursa (job #1137839) | Cod sursa (job #1566039)
#include <iostream>
#include <fstream>
#include <vector>
#define MOD 650359
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
vector<long> bucket[MOD];
void hash_insert(long x);
void hash_delete(long x);
vector<long>::iterator hash_find(long x);
int main()
{
int n, op;
long x;
for (fin >> n; n; --n)
{
fin >> op >> x;
switch(op)
{
case 1:
{
hash_insert(x);
} break;
case 2:
{
hash_delete(x);
} break;
case 3:
{
if (hash_find(x) != bucket[x % MOD].end())
fout << "1\n";
else
fout << "0\n";
} break;
default:
{ } break;
}
}
return 0;
}
void hash_insert(long x)
{
int index = x % MOD;
if (hash_find(x) == bucket[index].end())
bucket[index].push_back(x);
}
void hash_delete(long x)
{
int index = x % MOD;
vector<long>::iterator it = hash_find(x);
if (hash_find(x) != bucket[index].end())
bucket[index].erase(it);
}
vector<long>::iterator hash_find(long x)
{
int index = x % MOD;
for (vector<long>::iterator it = bucket[index].begin(); it != bucket[index].end(); it++)
if (*it == x)
return it;
return bucket[index].end();
}