Pagini recente » Cod sursa (job #2604050) | Cod sursa (job #1136303) | Cod sursa (job #2974336) | Cod sursa (job #1445647) | Cod sursa (job #2773596)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
// https://www.geeksforgeeks.org/c-program-hashing-chaining/
class Hash
{
vector<unsigned long long> table[10000];
public:
void insertItem(int x);
void deleteItem(int key);
bool findItem(int x,int key);
int hashFunction(int x) {
return (x % 10000);
}
};
void Hash::insertItem(int key)
{
int index = hashFunction(key);
table[index].push_back(key);
}
void Hash::deleteItem(int key)
{
int index = hashFunction(key);
for(int i = 0; i < table[index].size(); i++){
if (table[index][i] == key)
table[index].erase(table[index].begin() + i);
break;
}
}
bool Hash::findItem(int x, int key){
int index = hashFunction(key);
for(int i = 0; i < table[index].size(); i++){
if (table[index][i] == key)
return true;
}
return false;
}
int main()
{
int n;
int operatie, x;
fin>>n;
Hash hashSet;
for(int i = 1;i<=n;++i){
fin>>operatie>>x;
if(operatie == 1 && !hashSet.findItem(i, x)){
hashSet.insertItem(x);
}
else if(operatie == 2){
hashSet.deleteItem(x);
}
else{
if(!hashSet.findItem(i, x)){
fout<<0<<"\n";
}
else fout<<1<<"\n";
}
}
return 0;
}