Pagini recente » Cod sursa (job #1574728) | Cod sursa (job #2337330) | Cod sursa (job #2863689) | Cod sursa (job #2948334) | Cod sursa (job #1077495)
#include <cstdio>
#include <vector>
using namespace std;
int n,m=666013,parametru,tip;
FILE *f,*g;
vector<int> my_hash[666013];
int cauta(int x)
{
int indice=x % m;
for (int i=0;i<my_hash[indice].size();i++)
if (my_hash[indice][i]==x) return 1;
return 0;
}
void adauga(int x)
{
int indice=x % m;
if (cauta(x)==0)
my_hash[indice].push_back(x);
}
void sterge(int x)
{
int indice=x % m;
for (int i=0;i<my_hash[indice].size();i++)
if (my_hash[indice][i]==x)
{
my_hash[indice][i]=my_hash[indice].back();
my_hash[indice].pop_back();
break;
}
}
int main()
{
f=fopen("hashuri.in","r");
g=fopen("hashuri.out","w");
fscanf(f,"%d",&n);
for (int i=1;i<=n;i++)
{
fscanf(f,"%d%d",&tip,¶metru);
if (tip==1) adauga(parametru);
if (tip==2) sterge(parametru);
if (tip==3) fprintf(g,"%d\n",cauta(parametru));
}
fclose(f);
fclose(g);
return 0;
}