Pagini recente » Cod sursa (job #1419892) | Cod sursa (job #1162474) | Cod sursa (job #964224) | Cod sursa (job #700636) | Cod sursa (job #1562995)
#include <iostream>
#include <cstdio>
#define M 3999971
using namespace std;
struct nod
{
int val;
nod *next;
nod(int v=0) { this->val = v; this->next = NULL; }
};
nod* hashMap[M];
int getHash(int key)
{
return key%M;
}
void addKey(int key)
{
nod *x = new nod(key);
x->next = hashMap[getHash(key)];
hashMap[getHash(key)] = x;
}
nod* get(int key)
{
for (nod *crt = hashMap[getHash(key)]; crt != NULL; crt = crt->next)
if (crt->val == key)
return crt;
return NULL;
}
void removeKey(int key)
{
nod **pls;
pls = &hashMap[getHash(key)];
for (nod *crt = hashMap[getHash(key)]; crt != NULL; pls = &(crt->next), crt = crt->next)
if (crt->val == key) {
*pls = crt->next;
delete crt;
}
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int n, op, key;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &op, &key);
switch (op) {
case 1: addKey(key); break;
case 2: removeKey(key); break;
default: printf("%d\n", get(key) != NULL);
}
}
return 0;
}