Pagini recente » Cod sursa (job #1756764) | Cod sursa (job #2258084) | Cod sursa (job #1136527) | Cod sursa (job #2647148) | Cod sursa (job #249147)
Cod sursa(job #249147)
#include<fstream>
#define r 665124
using namespace std;
struct nod
{
int info;
nod *adr;
};
nod *v[r];
ifstream in("hashuri.in");
ofstream out("hashuri.out");
void adaug (nod *&p,int x)
{
nod *q=new nod;
q->info=x;
q->adr=p;
p=q;
}
void sterge (nod *&p, int x)
{
if(p==NULL)
return;
nod *aux=new nod;
if(p->info==x)
{
aux=p;
p=p->adr;
delete aux;
return;
}
for (nod* q=p;q->adr;q=q->adr)
{
if(q->adr->info==x)
{
aux=p->adr;
p->adr=aux->adr;
delete aux;
return;
}
}
}
void raspuns (nod *&p, int x)
{
int contor=0;
while (p!=NULL)
{
if(p->info==x)
contor=1;
p=p->adr;
}
if(contor==1)
out<<1;
else out<<0;
out<<"\n";
}
int main ()
{
long int n,a,b;
in>>n;
while (n--)
{
in>>a;
in>>b;
if(a==1)
adaug(v[b%r],b);
if(a==2)
sterge(v[b%r],b);
if(a==3)
raspuns(v[b%r],b);
}
in.close ();
out.close ();
return 0;
}