Pagini recente » Cod sursa (job #1476118) | Cod sursa (job #2660161) | Cod sursa (job #2479739) | Cod sursa (job #3304284) | Cod sursa (job #1018038)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
struct nod
{
int v;
nod *next;
};
nod *a[41357]; int p=41357;
void h1(int x)
{nod *m=new nod;
m->v=x;
m->next=NULL;
if (a[x%p]==NULL)
{
a[x%p]=new nod;
a[x%p]=m;
}
else
{
nod *q=new nod;
q=a[x%p];
while (q->next!=NULL) q=q->next;
q->next=m;
}
return;
}
void h2(int x)
{
if (a[x%p]!=NULL)
{
nod *q=new nod;
nod *m=new nod;
if (a[x%p]->v==x){ a[x%p]=NULL;return;}
else {m=a[x%p];
q=m->next;
while (m->next!=NULL)
if (q->v==x) {
m=q->next;
delete q;
return;
}
else {m=q; q=q->next;}}}
return;
}
void h3(int x)
{if (a[x%p]!=NULL) {
if (a[x%p]->v==x){g<<1<<"\n"; a[x%p]=a[x%p]->next; return;}
else {
nod *m=new nod;
m=a[x%p];
while (m->next!=NULL || m==NULL)
if (m->v==x){ g<<1<<"\n";return;}
else m=m->next;
g<<0<<"\n";return;
}}
else g<<0<<"\n";
return;
}
int main()
{int i,n,x,y;
f>>n;
for (i=0;i<p;i++) a[i]=NULL;
for (i=0;i<n;i++)
{
f>>y>>x;
if (y==1) h1(x);
else if (y==2) h2(x);
else h3(x);
}
f.close();
g.close();
return 0;
}