Pagini recente » Cod sursa (job #2313285) | Cod sursa (job #1285391) | Cod sursa (job #3242785) | Cod sursa (job #1521728) | Cod sursa (job #625928)
Cod sursa(job #625928)
#include <fstream>
#define max 666013
using namespace std;
struct point {
int inf;
point *leg;
};
point *h[max];
bool cautare (int x)
{
bool ok;
int i;
point *p;
i=x%max;
p=h[i];
ok=false;
while (p) {
if (p->inf==x) {ok=true;break;}
p=p->leg;
}
return ok;
}
void inserare (int x)
{
int i;
point *p;
i=x%max;
p=new point;
p->inf=x;
p->leg=h[i];
h[i]=p;
}
void stergere (int x)
{
point *p,*u;
int i;
i=x%max;
p=h[i];
u=h[i];
while (p->inf!=x &&p) {u=p;p=p->leg;}
if (p) if (u==p)
{
h[i]=h[i]->leg;
delete p;
}
else
{
u->leg=p->leg;
delete p;
}
}
int n,j,a,b;
bool ok1;
int main()
{
ifstream f("hashuri.in");
ofstream g("hashuri.out");
f>>n;
for (j=1;j<=n;j++) {
f>>a>>b;
if (a==1) {
ok1=cautare(b);if (ok1==false) inserare(b); }
if (a==2) {
ok1=cautare(b);if (ok1) stergere(b);}
if (a==3) {
ok1=cautare(b); if (ok1) g<<1<<'\n';
else g<<0<<'\n'; }
}
f.close();
g.close();
return 0;
}