Pagini recente » Cod sursa (job #291910) | Cod sursa (job #2094423) | Utilizatori inregistrati la Info Oltenia 2018 Proba pe Echipe Clasele 11 - 12 | Cod sursa (job #1368107) | Cod sursa (job #2287523)
#include <fstream>
#include <vector>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int MOD = 666013;
vector <int> h[MOD]; /// hash
int convert(int val){
return val % MOD;
}
int search(int key, int val){
///checks if val already exists in the hash table
///-1 means that the value wasn't found
///any other value is the position of the value
int sz = h[key].size();
for(int i=0;i<sz;i++)
if(h[key][i] == val)
return i;
return -1;
}
void insertValue(int val){
int key = convert(val);
int address = search(key,val);
if(address == -1)
h[key].push_back(val);
}
void deleteValue(int val){
int key = convert(val);
int address = search(key,val);
if(address != -1)
h[key].erase(h[key].begin() + address);
}
bool findValue(int val){
int key = convert(val);
int pos = search(key,val);
if(pos == -1)
return false;
return true;
}
int main()
{
int n, q, val;
in>>n;
for(int i=1;i<=n;i++){
in>>q>>val;
if(q == 1)
insertValue(val);
else if(q == 2)
deleteValue(val);
else
out<<findValue(val)<<"\n";
}
in.close();
out.close();
return 0;
}