Pagini recente » Cod sursa (job #2093145) | Cod sursa (job #113695) | Cod sursa (job #1299849) | Cod sursa (job #1182216) | Cod sursa (job #1465621)
#include<iostream>
#include<fstream>
#include<string.h>
#define MOD 666013
using namespace std;
struct nod
{
int info;
nod* urm;
};
void add(nod *&start, int _info)
{
if(start == NULL)
{
start = new nod;
start->info = _info;
start->urm = NULL;
} else
{
nod *aux = start;
bool gasit = false;
if(aux->info == _info)
gasit = true;
while(aux->urm)
{
if(aux->info == _info)
{
gasit = true;
break;
}
aux = aux->urm;
}
if(!gasit)
{
nod *n = new nod;
n->info = _info;
n->urm = NULL;
aux->urm = n;
}
}
}
void del(nod *&start, int _info)
{
if(start!= NULL && start->info == _info)
{
nod *n = start;
start = start->urm;
delete n;
} else
{
nod *n = start;
while(n!= NULL)
{
if((n->urm!= NULL) && (n->urm->info == _info))
break;
n = n->urm;
}
if(n!=NULL)
{
nod *toDel = n->urm;
n->urm = n->urm->urm;
delete toDel;
}
}
}
void list(nod *start)
{
while(start)
{
cout<<start->info<<" ";
start = start->urm;
}
cout<<endl;
}
bool find(nod *start, int _info)
{
nod *n = start;
bool gasit = false;
while((n!= NULL) && !gasit)
{
if(n->info == _info)
gasit = true;
n = n->urm;
}
return gasit;
}
int main()
{
fstream fin, fout;
fin.open("hashuri.in");
freopen("hashuri.out", "w", stdout);
int N;
fin>>N;
int a,b;
nod *n[MOD+1];
memset(n,MOD+1, 0);
for(int i=0;i<N;i++)
{
fin>>a>>b;
if(a == 1)
{
add(n[b%MOD], b);
} else if(a==2)
{
del(n[b%MOD], b);
} else if(a==3)
{
if(find(n[b%MOD], b) == true)
printf("1\n");
else
printf("0\n");
}
}
fin.close();
fout.close();
return 0;
}