Pagini recente » Cod sursa (job #2931019) | Cod sursa (job #990811) | Cod sursa (job #2532601) | Cod sursa (job #369711) | Cod sursa (job #625662)
Cod sursa(job #625662)
#include <fstream>
#define M 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int q,x,n,i;
struct point {
int inf;
point *leg;
};
point *h[M];
void inserare (int x)
{
point *p;
int ind=x%M;
p=new point;
p->inf=x; p->leg=h[ind];
h[ind]=p;
}
bool caut (int x)
{
point *p;
int ind=x%M;
p=h[ind];
while (p)
{
if (p->inf==x) return true;
p=p->leg;
}
return false;
}
void sterge (int x)
{
point *p,*u;
int ind=x%M;
p=h[ind];u=h[ind];
while (p->inf!=x && p) {u=p; p=p->leg;}
if (p)
if (u==p)
{
h[ind]=h[ind]->leg;
delete p;
}
else
{
u->leg = p->leg;
delete p;
}
}
int main ()
{
f>>n;
for (i=1;i<=n;i++)
{
f>>q>>x;
if (q==1)
if (!caut(x)) inserare(x);
if (q==2)
if (caut(x)) sterge(x);
if (q==3)
if (caut(x)) g<<1<<'\n';
else g<<0<<'\n';
}
f.close();
g.close();
return 0;
}