Pagini recente » Cod sursa (job #2914688) | Cod sursa (job #1258820) | Cod sursa (job #2791838) | Cod sursa (job #1011130) | Cod sursa (job #2610125)
#include <iostream>
#include <fstream>
using namespace std;
#define P 500000
struct nod{nod *next; int info;};
nod *H[P], *h;
int find_x(int x)
{
int i = x%P;
for (h = H[i]; h; h = h -> next)
if (h -> info == x)
return 1;
return 0;
}
void insert_x(int x)
{
if (find_x(x) == 0)
{
int i = x % P;
h = new nod;
h -> info = x;
h -> next = H[i];
H[i] = h;
}
}
void delete_x(int x)
{
if (find_x(x) == 1)
{
int i = x % P;
h = H[i];
if (h -> info == x)
{
H[i] = h -> next;
delete h;
}
else
{
while ((h -> next) -> info != x)
h = h -> next;
nod *p = h -> next;
h -> next = p -> next;
delete p;
}
}
}
int main()
{
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int N, op, x, i;
fin >> N;
for (i = 0; i < N; i++)
{
fin >> op >> x;
if (op == 1)
insert_x(x);
else if (op == 2)
delete_x(x);
else if (op == 3)
fout << find_x(x) << '\n';
}
fin.close();
fout.close();
return 0;
}