Pagini recente » Cod sursa (job #558501) | Cod sursa (job #998193) | Cod sursa (job #793999) | Cod sursa (job #552239) | Cod sursa (job #644253)
Cod sursa(job #644253)
#include<iostream>
#include<vector>
#include<fstream>
#define prim 123457
using namespace std;
vector<long int>v[123460];
ifstream f("hash.in");
ofstream g("hash.out");
int existenta(long int x,long int cheia)
{
long int i;
for(i=0;i<v[cheia].size();i++)
if(v[cheia][i]==x)
return i;
return -1;
}
void inserare(long int x,long int cheia)
{
if(existenta(x,cheia)==-1)
v[cheia].push_back(x);
}
void stergere(long int x,long int cheia)
{
long int i,poz;
poz=existenta(x,cheia);
if(poz!=-1)
{
v[cheia][poz]=v[cheia][v[cheia].size()-1];
v[cheia].pop_back();
}
}
void citire()
{
long int i,N,instructiune,numar,cheia;
f>>N;
for(i=1;i<=N;i++)
{
f>>instructiune;
f>>numar;
cheia=numar%prim;
if(instructiune==1)
inserare(numar,cheia);
else
if(instructiune==2)
stergere(numar,cheia);
else
if(instructiune==3)
if(existenta(numar,cheia)==-1)
g<<0<<endl;
else
g<<1<<endl;
}
}
int main()
{
citire();
f.close();
g.close();
return 0;
}