Pagini recente » Cod sursa (job #1490802) | Cod sursa (job #129429) | Cod sursa (job #1045943) | Cod sursa (job #472002) | Cod sursa (job #2030769)
#include <fstream>
using namespace std;
const int p = 99991;
struct lista {
int val;
lista * next = NULL;
}* hashu[100000];
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
int main()
{
int n, op, x;
fin >> n;
for (int i=0; i <2000; i++) hashu[i] = NULL;
for (int i=1; i<=n; i++) {
fin >> op >> x;
if (op == 1)
{
if (hashu[x%p] != NULL)
{
lista *aux = hashu[x%p];
while (aux->next != NULL)
{
aux = aux->next;
}
lista *newlista = new lista;
newlista->val = x / p;
newlista->next = NULL;
aux->next = newlista;
}
else
{
lista *newlista = new lista;
newlista->val = x / p;
hashu[x%p] = newlista;
}
}
else if (op == 2) {
if (hashu[x%p] != NULL)
{
lista *aux = hashu[x%p], *ant;
if (aux->val == x / p && aux->next != NULL) {
hashu[x % p] = aux->next;
delete aux;
}
else if (aux->val == x / p) {
hashu[x%p] = NULL;
}
else
{
while (aux->next != NULL)
{
ant = aux;
aux = aux->next;
if (aux->val == x / p) break;
}
if (aux->val == x / p && aux->next)
ant->next = aux->next;
else if (aux->val == x) {
ant->next = NULL;
delete aux;
}
}
}
}
else {
if (hashu[x%p] != NULL)
{
lista *aux = hashu[x%p];
if (aux->val == x / p) {
fout << 1 << '\n';
}
else
{
while (aux->next != NULL)
{
aux = aux->next;
if (aux->val==x/p)
break;
}
if (aux->val == x / p)
fout << 1 << '\n';
else
fout << 0 << '\n';
}
}
else
fout << 0 << '\n';
}
}
return 0;
}