Pagini recente » Cod sursa (job #1408876) | Cod sursa (job #2890853) | Cod sursa (job #2966466) | Borderou de evaluare (job #508045) | Cod sursa (job #809028)
Cod sursa(job #809028)
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
#define prim 2565151
using namespace std;
vector <long>v[prim];
FILE*f;
FILE*g;
long caut(long x)
{
long i,rest;rest=x%prim;
for (i=0;i<v[rest].size();i++)
if (x==v[rest][i])
return i;
return -1;
}
long adauga(long x)
{
long rest;rest=x%prim;
if (caut(x)==-1)
v[rest].push_back(x);
}
long sterge(long x)
{
long poz,gasit,rest;rest=x%prim;
gasit=caut(x);
if (gasit!=-1)
{
poz=v[rest].size();
v[rest][gasit]=v[rest][poz];
v[rest].pop_back();
}
}
int main()
{
int n,i;
long x;
short op;
f=fopen("hashuri.in","r");
g=fopen("hashuri.out","w");
fscanf(f,"%d",&n);
for (i=1;i<=n;i++)
{
fscanf(f,"%d%d",&op,&x);
switch (op)
{case 1:adauga(x);break;
case 2:sterge(x);break;
case 3:if (caut(x)==-1) fprintf(g,"%d \n",0);
else fprintf(g,"%d \n",1);}
}
return 0;
}