Pagini recente » Cod sursa (job #1863160) | Cod sursa (job #2917953) | Cod sursa (job #2719021) | Cod sursa (job #1615922) | Cod sursa (job #625657)
Cod sursa(job #625657)
#include <fstream>
#define MOD 666013
using namespace std;
struct point {
int inf;
point *leg;
};
point *H[MOD];
int o,x,n,i;
void insert (int x)
{
point *p;
int ind = x % MOD;
p = new point;
p->inf = x;
p->leg = H[ind];
H[ind]=p;
}
bool caut (int x)
{
int ind=x % MOD;
point *p;
p=H[ind];
while (p)
{
if (p->inf == x) return true;
p=p->leg;
}
return false;
}
void erase (int x)
{
int ind=x % MOD;
point *p,*u;
p=H[ind]; u=H[ind];
while (p->inf!=x && p!=NULL) {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 ()
{
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
f >> n;
for (i=1; i<=n; i++)
{
f >> o;
if (o==1)
{
f>>x;
if (!caut(x)) insert (x);
}
if (o==2)
{
f>>x;
if (caut(x)) erase (x);
}
if (o==3)
{
f>>x;
if (caut(x)) g<<1<<endl;
else g<<0<<endl;
}
}
f.close();
g.close();
return 0;
}