Pagini recente » Cod sursa (job #351956) | Cod sursa (job #1884193) | Cod sursa (job #288480) | Cod sursa (job #1573958) | Cod sursa (job #625660)
Cod sursa(job #625660)
#include <fstream>
#define M 666013
using namespace std;
ifstream f("in.txt");
ofstream g("out.txt");
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;
}