Pagini recente » Cod sursa (job #307511) | Cod sursa (job #2657121) | Cod sursa (job #2298874) | Cod sursa (job #2799847) | Cod sursa (job #1047593)
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
#define mod 666013
vector<int> hashh[mod];
int find(vector<int> V[mod], int x){
int index = x%mod;
for (vector<int>::iterator i = V[index].begin(); i != V[index].end(); ++i){
if (*i == x){
return 1;
}
}
return 0;
}
bool insert(vector<int> V[mod], int x){
if (find(V, x) == 0){
V[x%mod].push_back(x);
return true;
}
return false;
}
bool sterge(vector<int> V[mod], int x){
int index = x%mod;
for (vector<int>::iterator i = V[index].begin(); i != V[index].end(); ++i){
if (*i == x){
V[index].erase(i);
return true;
}
}
return false;
}
int main(){
fstream f("hashuri.in");
ofstream o("hashuri.out");
int n = 0; f >> n;
int op = 0, x = 0;
for (int i = 0; i < n; i++){
f >> op >> x;
if (op == 1){
insert(hashh, x);
}
else if (op == 2){
sterge(hashh, x);
}
else if (op == 3){
o << find(hashh, x) << "\n";
}
}
}