Pagini recente » Cod sursa (job #90830) | Cod sursa (job #2235556) | Cod sursa (job #38353) | Cod sursa (job #972997) | Cod sursa (job #2783749)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int mod=666013;
const int base=89;
int operatii;
vector <int> v[mod+5];
int hesh(int n)
{
long long h=0, p=1;
while(n)
{
h += p * (n % 10);
h %= mod;
n /= 10;
p *= base;
}
return h;
}
void inserthash(int n)
{
int h = hesh(n);
vector <int> :: iterator it = find(v[h].begin(), v[h].end(), n);
if(it != v[h].end() && !v[h].empty())
return;
v[h].push_back(n);
}
void deletehash(int n)
{
int h = hesh(n);
vector <int> :: iterator it = find(v[h].begin(), v[h].end(), n);
if(it != v[h].end() && !v[h].empty())
v[h].erase(it);
}
void findhash(int n)
{
int h = hesh(n);
vector <int> :: iterator it = find(v[h].begin(), v[h].end(), n);
if(it != v[h].end() && !v[h].empty())
fout<<1<<'\n';
else
fout<<0<<'\n';
}
void solve()
{
int cerinta, x;
fin>>cerinta>>x;
if(cerinta==1)
inserthash(x);
if(cerinta==2)
deletehash(x);
if(cerinta==3)
findhash(x);
}
int main()
{
fin>>operatii;
while(operatii--)
solve();
return 0;
}