Pagini recente » Cod sursa (job #2361120) | Cod sursa (job #2211145) | Cod sursa (job #2435307) | Cod sursa (job #291733) | Cod sursa (job #749421)
Cod sursa(job #749421)
#include<fstream>
using namespace std;
#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)<<"\n";
}
f.close();
g.close();
return 0;
}