Pagini recente » Cod sursa (job #615863) | Cod sursa (job #213622) | Cod sursa (job #2814617) | Cod sursa (job #2161942) | Cod sursa (job #2760132)
#include <iostream>
#include <fstream>
using namespace std;
const int P = 666019;
const int N_MAX = 1000001;
int nr_op, valori[N_MAX], liste[P + 1], urmator[N_MAX], nr_valori;
bool exista(int el){
int cheie_hash = el % P;
int x = liste[cheie_hash];
while (x != -1){
if (valori[x] == el){
return true;
}
x = urmator[x];
}
return false;
}
void adaugare(int el){
if (exista(el)){
return;
}
int cheie_hash = el % P;
valori[nr_valori] = el;
urmator[nr_valori] = liste[cheie_hash];
liste[cheie_hash] = nr_valori;
nr_valori++;
}
void stergere(int el){
int cheie_hash = el % P;
int x = liste[cheie_hash];
while (x != -1 && valori[x] != el){
x = urmator[x];
}
if (x != -1){
valori[x] = valori[liste[cheie_hash]];
liste[cheie_hash] = urmator[liste[cheie_hash]];
}
}
int main()
{
ifstream fi ("hashuri.in");
ofstream fo ("hashuri.out");
for (int i = 0; i < P; i++)
{
liste[i] = -1;
}
fi >> nr_op;
for (int i = 0; i < nr_op; i++){
int tip;
int x;
fi >> tip;
if (tip == 1){
fi >> x;
adaugare(x);
} else if (tip == 2){
fi >> x;
stergere(x);
} else {
fi >> x;
if (exista(x)){
fo << "1\n";
} else {
fo << "0\n";
}
}
}
fi.close();
fo.close();
return 0;
}