Pagini recente » Cod sursa (job #3137734) | Cod sursa (job #149579) | Cod sursa (job #575421) | Cod sursa (job #697492) | Cod sursa (job #2378706)
#include <fstream>
#include <map>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
InParser f("hashuri.in");
ofstream g("hashuri.out");
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;
f >> n;
for(i=1; i<=n; ++i){
f >> 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:
g << !(M.find(x) == M.end()) << '\n';
break;
}
}
return 0;
}