Pagini recente » Cod sursa (job #3131845) | Cod sursa (job #569183) | Cod sursa (job #997425) | Cod sursa (job #1792894) | Cod sursa (job #2217150)
#include <fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
struct myhash
{
int x;
myhash *next;
};
const int hash_size = 666013;
int N;
myhash *H[hash_size];
inline int h(int x)
{
return x % hash_size;
}
myhash* find(int x, myhash *H)
{
for(myhash *p = H; p != NULL; p = p->next)
if(p->x == x)
return p;
return NULL;
}
void add(int x, myhash *&H)
{
myhash *nou = new myhash;
nou->x = x;
nou->next = H;
H = nou;
}
void insert(int x, myhash *&H)
{
if(find(x, H) == NULL)
add(x, H);
}
void erase(int x, myhash *&H)
{
myhash *p = find(x, H);
if(p != NULL)
{
if(p != H)
p->next = p->next->next;
else
H = H->next;
}
}
int main()
{
in >> N;
int op, x;
for(int i = 1; i <= N; i++)
{
in >> op >> x;
if(op == 1)
insert(x, H[h(x)]);
if(op == 2)
erase(x, H[h(x)]);
if(op == 3)
out << ((find(x, H[h(x)]) == NULL) ? 0 : 1) << '\n';
}
return 0;
}