Pagini recente » Cod sursa (job #1413824) | Cod sursa (job #3189670) | Cod sursa (job #2897630) | Cod sursa (job #1236360) | Cod sursa (job #1047717)
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
#define prim 666013
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;
}
void adauga(long x)
{
long rest;rest=x%prim;
if (caut(x)==-1)
v[rest].push_back(x);
}
void sterge(long long x)
{
long poz,gasit,rest;rest=x%prim;
gasit=caut(x);
if (gasit!=-1)
{
poz=v[rest].size()-1;
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;
}