Pagini recente » Cod sursa (job #70623) | Cod sursa (job #285402) | Cod sursa (job #588969) | Cod sursa (job #3129148) | Cod sursa (job #3129252)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int valueHash = 666100;
vector<int> Hash[valueHash + 1];
int N, comanda, x;
int findInHash(int x) { //functie care determina daca valoarea x se afla in hash
int xHash = x % valueHash;
for (int j = 0; j < Hash[xHash].size(); j++) {
if (Hash[xHash][j] == x)
return j; // daca il gaseste returneaza pozitia lui
}
return -1;
}
int main(){
in >> N;
for (int i = 0; i < N; i++) {
in >> comanda >> x;
if (comanda == 1) { //il vom insera pe x in hash daca nu este deja stocat
if (findInHash(x) == -1)
Hash[x % valueHash].push_back(x);
} else if (comanda == 2) { //stergem pe x
int poz = findInHash(x);
if (poz != -1) {//daca x se afla in hash stergem elementul de pe pozitia returnata de functie
Hash[x % valueHash].erase(Hash[x % valueHash].begin() + poz);
}
} else { //verificam daca x este in multime
out << (findInHash(x) == - 1? 0 : 1) << '\n';
}
}
in.close();
out.close();
return 0;
}