Pagini recente » Cod sursa (job #2525989) | Cod sursa (job #1828817) | Cod sursa (job #1516178) | Cod sursa (job #2503881) | Cod sursa (job #2745699)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
#define prim 99079
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
struct HashMap{
vector<int> Map[prim];
void adauga(int x){
int h = x%prim;
if(find(Map[h].begin(),Map[h].end(),x) == Map[h].end()){
Map[h].push_back(x);
}
}
void sterge(int x){
int h = x%prim;
auto elem = find(Map[h].begin(),Map[h].end(),x);
if(elem != Map[h].end()){
Map[h].erase(elem);
}
}
int cauta(int x){
int h = x%prim;
if(find(Map[h].begin(),Map[h].end(),x) != Map[h].end()){
return 1;
}
else{
return 0;
}
}
};
int n,i,operatie,x;
int main(){
HashMap hashMap;
fin>>n;
for ( i = 0; i < n; i++){
fin>>operatie>>x;
switch(operatie){
case 1:
hashMap.adauga(x);
break;
case 2:
hashMap.sterge(x);
break;
case 3:
fout<<hashMap.cauta(x)<<"\n";
break;
}
}
fin.close();
fout.close();
return 0;
}