Pagini recente » Cod sursa (job #911199) | Cod sursa (job #542242) | Cod sursa (job #870526) | Cod sursa (job #2081820) | Cod sursa (job #780361)
Cod sursa(job #780361)
#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 a)
{
hash* q=new hash;
int modul;
q->x=a;
modul=e%m;
q->next=h[modul];
h[modul]=q;
}
int search(long a)
{
int modul;
modul=a%m;
hash* q=h[modul];
while(q)
{
if (q->x==a) return 1;
q=q->next;
}
return 0;
}
void del(int a)
{
int modul;
modul=a%m;
hash* q=h[modul];
if(q)
{
if(q->x==a)
h[modul]=q->next;
else
{
hash* p;
p=q;
q=q->next;
while(q)
{
if(q->x==a)
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;
}
}