Pagini recente » Cod sursa (job #2297416) | Cod sursa (job #3181845) | Cod sursa (job #1424927) | Cod sursa (job #1133258) | Cod sursa (job #377898)
Cod sursa(job #377898)
#include<fstream.h>
int p=666667,h[666668][10],cont[666668];
int caut(int key)
{
int rest=key%p,i,pozitie=0;
for(i=1;i<=cont[rest];i++)
if(h[rest][i]==key)
pozitie=i;
return pozitie;
}
void adaug(int key)
{
int rest=key%p;
if(!caut(key))
h[rest][++cont[rest]]=key;
}
void sterg(int key)
{
int rest=key%p,i,pozitie;
pozitie=caut(key);
if(pozitie)
for(i=pozitie;i<cont[rest];i++)
h[rest][i]=h[rest][i+1];
cont[rest]--;
}
int main()
{
int i,n,op,x;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
f>>n;
for(i=1;i<=n;i++)
{
f>>op>>x;
if(op==1)
adaug(x);
else
if(op==2)
sterg(x);
else
if(caut(x))
g<<"1\n";
else
g<<"0\n";
}
return 0;
}