Pagini recente » Cod sursa (job #39262) | Cod sursa (job #492104) | Cod sursa (job #1079636) | Cod sursa (job #245646) | Cod sursa (job #293536)
Cod sursa(job #293536)
#include <stdio.h>
const long mod=524287;
typedef struct nod {int val; nod* next;} *Lista;
Lista h[mod+20];
void inserare(int x)
{
int i;
Lista q;
i=x%mod;
q=h[i];
while (q!=NULL)
{
if (q->val==x) return;
q=q->next;
}
q=new nod;
q->val=x; q->next=h[i];
h[i]=q;
}
void stergere(int x)
{
int i;
Lista q,ant;
i=x%mod;
q=h[i]; ant=NULL;
while (q!=NULL)
{
if (q->val==x)
{
if (ant==NULL) { h[i]=h[i]->next; delete q;}
else
{
ant->next=q->next;
delete q;
}
return;
}
ant=q;
q=q->next;
}
}
int cauta(int x)
{
int i; Lista q;
i=x%mod;
q=h[i];
while (q!=NULL)
{
if (q->val==x) return 1;
q=q->next;
}
return 0;
}
int main()
{
FILE *fin=fopen("hashuri.in","r");
FILE *fout=fopen("hashuri.out","w");
int n,x,op;
fscanf(fin,"%d",&n);
while (n--)
{
fscanf(fin,"%d %d",&op,&x);
switch (op)
{
case 1: {inserare(x); break;}
case 2: {stergere(x); break;}
case 3: { fprintf(fout,"%d\n",cauta(x));}
}
}
return 0;
}