Pagini recente » Cod sursa (job #1478167) | Cod sursa (job #1990521) | Cod sursa (job #2714000) | Cod sursa (job #2438593) | Cod sursa (job #2294660)
#include<fstream>
#include<vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int PRIM = 191507;
vector<long> hash_table[1000001];
void adauga(long x){
long modulo = x % PRIM;
long ok = 0;
long long poz_libera = -1;
long long i;
for(i = 0 ; i < hash_table[modulo].size() && ok == 0 ; i++){
if(hash_table[modulo][i] == x)
ok = 1;
if(hash_table[modulo][i] == 0 && poz_libera == -1)
poz_libera = i;
}
if(ok == 0 && poz_libera >= 0){
ok = 1;
hash_table[modulo][poz_libera] = x;
}
if(ok == 0){
hash_table[modulo].push_back(x);
}
}
void sterge(long x){
long modulo = x % PRIM;
long ok = 0;
long long i;
for(i = 0 ; i < hash_table[modulo].size() && ok == 0 ; i++)
if(hash_table[modulo][i] == x){
ok = 1;
hash_table[modulo][i] = 0;
}
}
long verifica_daca_este_in_multime(long x){
long modulo = x % PRIM;
long ok = 0;
long long i;
for(i = 0 ; i < hash_table[modulo].size() && ok == 0 ; i++)
if(hash_table[modulo][i] == x){
ok = 1;
}
return ok;
}
int main()
{
long n, cerinta, x;
f>>n;
for(long i = 0 ; i < n ; i++){
f>>cerinta>>x;
if(cerinta == 1){
adauga(x);
}
if(cerinta == 2){
sterge(x);
}
if(cerinta == 3){
g<<verifica_daca_este_in_multime(x)<<'\n';
}
}
return 0;
}