Pagini recente » Cod sursa (job #1190151) | Cod sursa (job #2268030) | Cod sursa (job #2296850) | Cod sursa (job #3255747) | Cod sursa (job #774753)
Cod sursa(job #774753)
#include<fstream>
const int m=780683;
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[780683];
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;
}