Pagini recente » Cod sursa (job #2483301) | Cod sursa (job #1764617) | Cod sursa (job #1534112) | Cod sursa (job #1898474) | Cod sursa (job #868268)
Cod sursa(job #868268)
#include <fstream>
using namespace std;
#define clasa 210000
struct nod
{
int val;
nod *ante;
};
nod *v[clasa+1];
bool exista(int x)
{
nod *p;
bool gasit=false;
for(p=v[x%clasa];p!=NULL;p=p->ante)
if(p->val==x)
{
gasit=true;
break;
}
if(gasit)
return 1;
return 0;
}
void push(int x)
{
if(exista(x))
return;
nod *p=new nod;
p->val=x;
p->ante=v[x%clasa];
v[x%clasa]=p;
}
void pop(int x)
{
nod *p=new nod;
nod *t=new nod;
if(v[x%clasa]!=NULL)
if(v[x%clasa]->val==x)
{
v[x%clasa]=v[x%clasa]->ante;
return;
}
for(p=v[x%clasa];p!=NULL;p=p->ante)
{
if(p->val==x)
{
if(t!=NULL) //luam 40 cu t==null, prostie
t->ante=p->ante;
break;
}
t=p;
}
}
int main()
{
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n,x,y,i;
fin>>n;
for(i=0;i<n;i++)
{
fin>>x;
fin>>y;
if(x==1)
push(y);
else if(x==2)
pop(y);
else
fout<<exista(y)<<'\n';
}
fin.close();
fout.close();
return 0;
}