Pagini recente » Cod sursa (job #1226025) | Cod sursa (job #2637356) | Cod sursa (job #597628) | Cod sursa (job #1238502) | Cod sursa (job #1204472)
#include <fstream>
#include <vector>
#define _P 666013
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
struct nod
{
int info;
nod *next;
};
void add(vector <nod *> &, int );
void rem(vector <nod *> &, int );
bool look(vector <nod *> , int );
int main()
{
int n,op,x;
vector <nod *> H;
H.resize(_P);
fin>>n;
for(int i=0;i<n;i++)
{
fin>>op>>x;
switch(op)
{
case 1:
add(H,x);
break;
case 2:
rem(H,x);
break;
case 3:
fout<<look(H,x)<<"\n";
break;
}
}
return 0;
}
bool look(vector <nod *> H, int x)
{
int xx=x;
while(x>_P)
x-=_P;
nod *n=H[x];
while(n)
{
if(n->info == xx)
return true;
n=n->next;
}
return false;
}
void rem(vector <nod *> &H, int x)
{
int xx=x;
while(x>_P)
x-=_P;
if(!look(H,xx))
return;
nod *n=H[x];
if(H[x]->info == xx)
H[x]=H[x]->next;
while(n->next)
{
if(n->next->info == xx)
{
n->next=n->next->next;
break;
}
n=n->next;
}
}
void add(vector <nod *> &H, int x)
{
int xx=x;
while(x>_P)
x-=_P;
nod *n=new nod;
n->info=xx;
n->next=H[x];
H[x]=n;
}