Pagini recente » Cod sursa (job #409637) | Cod sursa (job #2157320) | Cod sursa (job #2363437) | Cod sursa (job #1925339) | Cod sursa (job #749419)
Cod sursa(job #749419)
#include<fstream.h>
#define H 666013
ifstream f("hashuri.in");
ofstream g("hashuri.out");
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 op, x, t;
f>>t;
while(t--) {
f>>op>>x;
if(op==1) {
if(!find(x))
insert(x);
}
else
if(op==2) {
if(find(x))
del(x);
}
else
g<<find(x);
}
f.close();
g.close();
return 0;
}