Pagini recente » Cod sursa (job #2221009) | Cod sursa (job #2198835) | Cod sursa (job #1932349) | Cod sursa (job #1377819) | Cod sursa (job #2456281)
#include<stdio.h>
#define H 666013
FILE * f = fopen("hashuri.in", "r");
FILE* g = fopen("hashuri.out", "w");
struct Nod
{
int e;
Nod* urm;
};
Nod* list[H];
void insert(int x)
{
int h;
h = x % H;
Nod* q;
q = new Nod;
q->e = x;
q->urm = list[h];
list[h] = q;
}
int find(int x)
{
int h = x % H;
Nod* q;
for (q = list[h]; q; q = q->urm)
if (x == q->e) return 1;
return 0;
}
void del(int x)
{
Nod* q;
int h = x % H;
if (list[h]->e == x)
{
Nod* q;
q = list[h];
list[h] = list[h]->urm;
delete(q);
return;
}
for (q = list[h]; q->urm; q = q->urm)
{
if (q->urm->e == x)
{
Nod* t = q->urm;
q->urm = q->urm->urm;
delete(t);
break;
}
}
}
int main()
{
int t;
fscanf(f, "%d", &t);
int op, x;
while (t--)
{
fscanf(f, "%d %d", &op, &x);
if (op == 1)
{
if (!find(x)) insert(x);
}
else if (op == 2)
{
if (find(x)) del(x);
}
else fprintf(g, "%d\n", find(x));
}
return 0;
}