Pagini recente » Cod sursa (job #2453134) | Cod sursa (job #713345) | Cod sursa (job #1155271) | Cod sursa (job #321240) | Cod sursa (job #2788648)
#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 c;
vector <int> v[mod+5];
int hsh(int x)
{
long long h=0, p=1;
while(x)
{
h+=p*(x%10);
h%=mod;
x/=10;
p*=base;
}
return h;
}
void adauga(int x)
{
int h = hsh(x);
vector <int> :: iterator it = find(v[h].begin(), v[h].end(), x);
if(it != v[h].end() && !v[h].empty())
return;
v[h].push_back(x);
}
void sterge(int x)
{
int h = hsh(x);
vector <int> :: iterator it = find(v[h].begin(), v[h].end(), x);
if(it != v[h].end() && !v[h].empty())
v[h].erase(it);
}
void afis(int x)
{
int h = hsh(x);
vector <int> :: iterator it = find(v[h].begin(), v[h].end(), x);
if(it != v[h].end() && !v[h].empty())
fout<<1<<"\n";
else
fout<<0<<"\n";
}
void solve()
{
fin>>c;
while(c--)
{
int cerinta, x;
fin>>cerinta>>x;
if(cerinta==1)
adauga(x);
if(cerinta==2)
sterge(x);
if(cerinta==3)
afis(x);
}
}
int main()
{
solve();
return 0;
}