Pagini recente » Cod sursa (job #1823883) | Cod sursa (job #615935) | Cod sursa (job #3216843) | Cod sursa (job #495599) | Cod sursa (job #854259)
Cod sursa(job #854259)
#include<iostream>
#include<vector>
#include<fstream>
#define MOD 666013
using namespace std;
vector<int> H[MOD];
vector<int>::iterator cauta(int x)
{
int element = x % MOD;
vector<int>::iterator it;
for(it = H[element].begin(); it != H[element].end(); ++it)
if(*it == x)
return it;
return H[element].end();
}
void adaug(int x)
{
int element = x % MOD;
if(cauta(x) == H[element].end())
H[element].push_back(x);
}
void sterg(int x)
{
int element = x % MOD;
if(cauta(x) != H[element].end())
H[element].erase(cauta(x));
}
int main()
{
short op;
unsigned int x,N;
ifstream input("hashuri.in");
ofstream output("hashuri.out");
input >> N;
for(unsigned i = 0 ; i < N ; i++)
{
input >> op >> x;
if( op == 1 )
{
adaug(x);
continue;
}
else if ( op == 2 )
{
sterg(x);
continue;
}
else if ( op == 3 )
{
bool rezultat = cauta(x) != H[x %MOD].end();
output << rezultat << "\n";
}
}
input.close();
output.close();
return 0;
}