Pagini recente » Cod sursa (job #2615141) | Cod sursa (job #819174) | Cod sursa (job #220415) | Cod sursa (job #2612325) | Cod sursa (job #780359)
Cod sursa(job #780359)
#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)<<" ";
}
}