Pagini recente » Cod sursa (job #499886) | Cod sursa (job #2409908) | Cod sursa (job #706878) | Cod sursa (job #167141) | Cod sursa (job #809197)
Cod sursa(job #809197)
#include<stdio.h>
#include<vector>
using namespace std;
vector <int> Hash[666013];
int N;
FILE *f=fopen("hashuri.in","r");
FILE *g=fopen("hashuri.out","w");
int cauta(int el)
{
int ind;
vector <int>:: iterator it;
ind=el%666013;
for(it = Hash[ind].begin(); it!=Hash[ind].end(); ++it)
if(*it == el)
return 1;
return 0;
}
void inserare(int el)
{
int ind;
ind=el%666013;
if (cauta(el)==0)
{
Hash[ind].push_back(el);
}
}
void stergere(int el)
{
if (cauta(el)==1)
{
int ind;
vector <int>:: iterator it;
ind=el%666013;
for(it=Hash[ind].begin();it!=Hash[ind].end();++it)
if (*it==el)
{
Hash[ind].erase(it);
break;
}
}
}
int main()
{
int op, el, i;
fscanf(f,"%d",&N);
for(i=1;i<=N;i++)
{
fscanf(f,"%d %d",&op, &el);
if (op==1)
inserare(el);
if (op==2)
stergere(el);
if (op==3)
if (cauta(el)==1)
fprintf(g,"1\n");
else
fprintf(g,"0\n");
}
fclose(f);
fclose(g);
return 0;
}