Pagini recente » Cod sursa (job #97426) | Cod sursa (job #719439) | Cod sursa (job #1118893) | Cod sursa (job #664808) | Cod sursa (job #1550073)
#include <fstream>
#define prim 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int i,n,x,y;
struct lista
{
int info;
lista *next;
}
*Hash[prim];
void adauga(lista *&p, int y)
{
lista *q;
for(q=p;q&&q->info!=y;q=q->next);
if(q) return;
q=new lista;
q->info=y;
q->next=p;
p=q;
}
void cauta(lista *p, int y)
{
lista *q;
for (q = p; q; q = q -> next)
if (q -> info == y)
{
g<<1<<endl;
return;
}
g<<0<<endl;
}
void sterge(lista *&p, int val)
{
lista *q, *w;
for (q=p; q&&q->info!=val; q=q->next);
if (q==NULL) return;
if (q==p)
{
w=p;
p=p->next;
delete w;
}
else
{
w=q;
q=w->next;
delete w;
}
}
int main()
{
f>>n;
while(n);
{
f>>x>>y;
if (x==1) adauga(Hash[y % prim],y);
if (x==2) sterge(Hash[y % prim],y);
if (x==3) cauta (Hash[y % prim],y);
n--;
}
return 0;
}