Pagini recente » Cod sursa (job #3127228) | 123456789 | Cod sursa (job #509160) | Cod sursa (job #3214498) | Cod sursa (job #629342)
Cod sursa(job #629342)
#include <iostream>
#include <cstdio>
#include <list>
using namespace std;
#define MAX_P 666013
int n;
list <int> myhash[MAX_P];
int hash (int x) {
return x % MAX_P;
}
void hash_add (int x) {
myhash[hash(x)].push_back (x);
}
void hash_del (int x) {
myhash[hash(x)].remove (x);
}
int hash_exists (int x) {
int poz = hash(x);
for (list<int>::iterator it = myhash[poz].begin (); it != myhash[poz].end
(); it ++ )
if (*it == x)
return 1;
return 0;
}
int main () {
freopen ("hashuri.in", "r", stdin);
freopen ("hashuri.out", "w", stdout);
int op, nr;
cin >> n;
for (int i = 0; i < n; i ++) {
cin >> op >> nr;
switch (op) {
case 1: {
hash_add (nr);
break;
}
case 2: {
hash_del (nr);
break;
}
case 3: {
cout << hash_exists (nr) << '\n';
break;
}
}
}
return 0;
}