Pagini recente » Cod sursa (job #500896) | Cod sursa (job #350520) | Cod sursa (job #671859) | Cod sursa (job #18691) | Cod sursa (job #2888164)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int P=666013;
int base=97;
vector <int> H[P+5];
int Hash(int x)
{
int rasp=0, p=1;
while(x!=0)
{
int cif=x%10;
x=x/10;
rasp=rasp+cif*p;
rasp=rasp%P;
p=p*base;
p=p%P;
}
return rasp;
}
int main()
{
int n;
fin>>n;
for(int op=1;op<=n;op++)
{
int oper, x;
fin>>oper>>x;
int nr_hash=Hash(x);
auto it = find(H[nr_hash].begin(), H[nr_hash].end(), x);
if(oper==1 && it==H[nr_hash].end())
{
H[nr_hash].push_back(x);
}
if(oper==2 && it!=H[nr_hash].end())
{
H[nr_hash].erase(it);
}
if(oper==3)
{
if(it!=H[nr_hash].end())
{
fout<<1<<'\n';
}
else
{
fout<<0<<'\n';
}
}
}
return 0;
}