Pagini recente » Cod sursa (job #658182) | Cod sursa (job #3126706) | Cod sursa (job #1780490) | Cod sursa (job #1392028) | Cod sursa (job #1047716)
#include<fstream>
#define ro 666013
using namespace std;
ifstream fi("hashuri.in");
ofstream fo("hashuri.out");
struct nod{
int info;
nod *next;
};
nod *a[ro],*q,*p;
int t,i,oper,x;
int apartine(int x){
int k=x%ro;
q=a[k];
while(q!=NULL && q->info!=x) q=q->next;
if(q!=NULL) return 1;
else return 0;
}
void adauga(int x){
int k=x%ro;
q=new nod;
q->info=x;
q->next=a[k];
a[k]=q;
}
void sterge(int x){
int k=x%ro;
q=a[k];
if(q->info==x){
a[k]=q->next;
delete q;
}
else {
p=q;
while(q!=NULL && q->info!=x) { p=q; q=q->next; }
p->next=q->next;
delete q;
}
}
int main(){
fi>>t;
for(i=0;i<ro;i++) a[i]=NULL;
for(i=1;i<=t;i++){
fi>>oper>>x;
if(oper==1){
if(apartine(x)==0) adauga(x);
}
else if(oper==2){
if(apartine(x)) sterge(x);
}
else if(oper==3){
if(apartine(x)) fo<<"1\n";
else fo<<"0\n";
}
}
fi.close();
fo.close();
return 0;
}