Pagini recente » Cod sursa (job #53847) | Cod sursa (job #1914912) | Cod sursa (job #1812664) | Cod sursa (job #1173060) | Cod sursa (job #1446602)
#include <iostream>
#include <fstream>
#define Nmax 1000003
using namespace std;
fstream f("hashuri.in", ios::in);
fstream g("hashuri.out", ios::out);
struct nod
{
long long int info;
nod *urm;
}*h[Nmax];
inline int hashFunction(long long int x)
{
return x%Nmax;
}
void in(long long int x)
{
nod *p = h[hashFunction(x)];
while(p->urm && p->info != x)
p = p->urm;
if(p->info != x)
{
nod *nou = new nod;
nou->info = x;
nou->urm = NULL;
p->urm = nou;
}
}
void out(long long int x)
{
nod *p = h[hashFunction(x)];
while(p->urm && p->info != x)
if(p->urm->info == x)
{
nod *r = p->urm;
p->urm = r->urm;
delete r;
return;
}
}
int cauta(long long int x)
{
nod *p = h[hashFunction(x)];
while(p->urm && p->info != x)
p = p->urm;
return (p->info == x);
}
int main()
{
for(int i = 0; i < Nmax; ++i)
{
h[i] = new nod;
h[i]->urm = NULL;
h[i]->info = -1;
}
int n;
f>>n;
for(int i = 0; i < n; ++i)
{
int a;
long long int x;
f>>a>>x;
if(a == 1)
in(x);
if(a == 2)
out(x);
if(a == 3)
g<<cauta(x)<<'\n';
}
return 0;
}