Pagini recente » Cod sursa (job #1152714) | Cod sursa (job #341331) | Cod sursa (job #1799367) | Cod sursa (job #2012748) | Cod sursa (job #774759)
Cod sursa(job #774759)
#include<fstream>
const int m=666013;
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n,i,c;
long e;
struct hash
{long x;
hash* next;};
hash* h[666013];
void add(long elem)
{hash* q = new hash;
int modl;
q->x=elem;
modl=e%m;
q->next=h[modl];
h[modl]=q;
}
int search(long elem)
{int modl;
modl=e%m;
hash* q=h[modl];
while(q)
{if(q->x==elem)
return 1;
q=q->next;}
return 0;
}
void del(int elem)
{int modl;
modl=e%m;
hash* q=h[modl];
if(q)
{if(q->x==elem)
h[modl]=q->next;
else
{hash* p;
p=q;
q=q->next;
while(q)
{if(q->x==elem)
p->next=q->next;
q=q->next;}
}
}
}
int main()
{
f>>n;
for(i=1; i<=n; i++)
{f>>c>>e;
if(c==1)
add(e);
if(c==2)
del(e);
if(c==3)
g<<search(e)<<endl;
}
f.close();
g.close();
return 0;
}