Pagini recente » Cod sursa (job #2415033) | Cod sursa (job #2221798) | Cod sursa (job #2468948) | Cod sursa (job #1465120) | Cod sursa (job #1797427)
#include <iostream>
#include <fstream>
using namespace std;
#define M 123457
struct nod
{
int nr;
nod *link;
}*HT[M];
void push(int, int);
void delete_x(int, int);
nod* gaseste_x(int, int);
int main()
{
int n, o, x,h;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
cin >> n;
for (; n; n--)
{
cin >> o >> x;
h = x%M;
if (o == 1)
{
push(h, x);
}
else if (o == 2)
{
delete_x(h, x);
}
else
{
if(gaseste_x(h, x)) cout << 1 << endl;
else cout << 0 << endl;
}
}
return 0;
}
void push(int h, int x)
{
nod *a = new nod;
if (gaseste_x(h, x)) return;
a->nr = x;
a->link = HT[h];
HT[h] = a;
}
void delete_x(int h, int x)
{
nod *p,*aux;
p = gaseste_x(h, x);
if (p)
{
p->nr = HT[h]->nr;
aux = HT[h];
HT[h] = HT[h]->link;
delete aux;
}
}
nod* gaseste_x(int h, int x)
{
nod *p = HT[h];
while (p)
{
if (p->nr == x) return p;
p = p->link;
}
return 0;
}