Pagini recente » Cod sursa (job #2803689) | Cod sursa (job #689143) | Cod sursa (job #323461) | Cod sursa (job #1795427) | Cod sursa (job #2376815)
#include<cstdio>
#define MOD 666013
using namespace std;
struct node {
int val;
node* next;
};
node* g[MOD];
inline int h(int x) {
return x % MOD;
}
bool searchKey(int x) {
int poz = h(x);
node* p = g[poz];
while(p != NULL && p->val != x)
p = p->next;
if(p != NULL)
return true;
return false;
}
void insertKey(int x) {
int poz = h(x);
node* elem = new node;
elem->val = x;
elem->next = g[poz];
g[poz] = elem;
}
void deleteKey(int x) {
int poz = h(x);
node *p, *q;
p = g[poz];
if(p->val == x) {
q = p;
g[poz] = g[poz]->next;
delete q;
} else {
while(p != NULL && p->next->val != x)
p = p->next;
q = p->next;
p->next = q->next;
delete q;
}
}
int main() {
int op, x, n, i;
FILE* fin, *fout;
fin = fopen("hashuri.in","r");
fout = fopen("hashuri.out","w");
fscanf(fin,"%d",&n);
for(i = 1; i <= n; i++) {
fscanf(fin,"%d%d",&op,&x);
if(op == 1) {
if(!searchKey(x))
insertKey(x);
} else if(op == 2) {
if(searchKey(x))
deleteKey(x);
} else fprintf(fout,"%d\n",searchKey(x));
}
fclose(fin);
fclose(fout);
return 0;
}