Pagini recente » Cod sursa (job #1705092) | Cod sursa (job #1569595) | Cod sursa (job #1998235) | Cod sursa (job #3198569) | Cod sursa (job #561671)
Cod sursa(job #561671)
#include <iostream>
#include <fstream>
using namespace std;
#define INFILE "hashuri.in"
#define OUTFILE "hashuri.out"
ifstream fin (INFILE);
ofstream fout (OUTFILE);
#define MOD 660053
struct nod{
int val;
nod* next;
};
nod* table[MOD];
int contains(int x)
{
nod* n = table[x % MOD];
while( n!=NULL)
{
if( n->val==x )
return 1;
n = n->next;
}
return 0;
}
void add(int x)
{
nod* n = table[x % MOD];
if( n==NULL )
{
nod* nx = new nod();
nx->val = x;
nx->next = NULL;
table[x % MOD] = nx;
}
else
{
if( n->val==x )
return;
while( n->next!=NULL && n->next->val!=x )
n = n->next;
if( n->next==NULL )
{
nod* nx = new nod();
nx->val = x;
nx->next = NULL;
n->next = nx;
}
}
}
void del(int x)
{
nod* n = table[x % MOD];
if( n==NULL )
return;
if( n->val==x )
{
table[x % MOD] = n->next;
delete n;
}
else
while( n->next!=NULL )
{
if( n->next->val==x )
{
nod* aux = n->next;
n->next = aux->next;
delete aux;
}
n = n->next;
}
}
int main()
{
int n, nr;
int op;
memset(table, NULL, sizeof(table));
fin >> n;
while( n-- )
{
fin >> op >> nr;
if( op==1 ) add(nr);
else if( op==2 ) del(nr);
else fout << contains(nr) << endl;
}
return 0;
}