Pagini recente » Cod sursa (job #1389041) | Cod sursa (job #404209) | Cod sursa (job #1495788) | Cod sursa (job #258627) | Cod sursa (job #2745330)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> h[1000];
int hashh(int x){
return x%991;
}
bool semaf(int x){
int ind = hashh(x);
for(int i=0;i<h[ind].size();i++){
if(h[ind][i] == x) return true;
}
return false;
}
void push(int x){
if(!semaf(x)){
int ind = hashh(x);
h[ind].push_back(x);
}
}
void pop(int x){
int ind = hashh(x);
for(int i=0;i<h[ind].size();i++){
if(h[ind][i]==x){
h[ind].erase(h[ind].begin()+i);
return;
}
}
}
int main(){
int n, operatie, x;
f>>n;
for(int i=0;i<n;i++){
f>>operatie>>x;
if(operatie == 1)
push(x); // op 1=> adaug x
else{
if(operatie == 2)
pop(x); // op 2=> sterg \x
else g<<semaf(x)<<'\n'; // afisez pe varianta 3
}
}
return 0;
}