Pagini recente » Cod sursa (job #2623597) | Cod sursa (job #1349471) | Cod sursa (job #2462388) | Cod sursa (job #580777) | Cod sursa (job #2623276)
#include <iostream>
#include<vector>
#include <algorithm>
#include <fstream>
using namespace std;
const int P=999983;
vector<long long> Hash[P];
int cautare(long long x)
{
int index=x%P;
if(find(Hash[index].begin(),Hash[index].end(),x)==Hash[index].end())
return 0; ///nu a fost gasit
return 1; ///a fost gasit
}
void inserare(long long x)
{
int index=x%P;
if(cautare(x)==0)
Hash[index].push_back(x);
}
void stergere(long long x)
{
int index=x%P;
if(cautare(x)==1)
{
vector<long long >::iterator it;
it=find(Hash[index].begin(),Hash[index].end(),x);
Hash[index].erase(it);
}
}
int main()
{
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n;
in>>n;
for(int i=0;i<n;i++)
{
int opt;
in>>opt;
switch(opt)
{
case 1:
{
long long value;
in>>value;
inserare(value);
break;
}
case 2:
{
long long value;
in>>value;
stergere(value);
break;
}
case 3:
{
long long value;
in>>value;
out<<cautare(value)<<"\n";
break;
}
}
}
return 0;
}