Pagini recente » Cod sursa (job #1555278) | Cod sursa (job #2884607) | Cod sursa (job #1690404) | Cod sursa (job #3141485) | Cod sursa (job #2378710)
#include<cstdio>
#include <map>
using namespace std;
unsigned int getHash(int x)
{
//Return hash value of x as the pos in the hash table
unsigned int hs = 5381;
while(x > 0){
hs = ((hs << 5) + hs) + ((x % 10) + 33); /* hs * 33 + (x % 10) */
x /= 10;
}
return hs;
}
int n, op, x;
map <unsigned int, int> M;
int main()
{
int i;
FILE *f, *g;
f = fopen("hashuri.in", "r");
g = fopen("hashuri.out", "w");
fscanf(f, "%d", &n);
for(i=1; i<=n; ++i){
fscanf(f, "%d%d", &op, &x);
switch(op){
case 1:
if(M.find(x) == M.end())
M.insert({x, getHash(x)});
break;
case 2:
M.erase(x);
break;
case 3:
fprintf(g, "%d\n", !(M.find(x) == M.end()));
break;
}
}
return 0;
}