Pagini recente » Cod sursa (job #229556) | Cod sursa (job #427407) | Cod sursa (job #1061707) | Cod sursa (job #3235123) | Cod sursa (job #2744650)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int>::iterator it;
vector<int> h[100];
int n, operatie, x;
int hash_func(int x){
return x%31;
}
void pop(int x){
int poz = hash_func(x);
for(it=h[poz].begin();it!=h[poz].end();it++){
if(*it == x){
h[poz].erase(it);
}
}
}
int index(int x){
int poz = hash_func(x);
for(it=h[poz].begin();it!=h[poz].end();it++){
if(*it == x){
return 1;
}
}
return 0;
}
void push(int x){
int poz = x%31;
if(index(x)){
h[poz].push_back(x);
}
}
int main(){
f>>n;
for(int i=0;i<n;i++){
f>>operatie>>x;
if(operatie == 1) push(x);
if(operatie == 2) pop(x);
if(operatie == 3) g<<index(x)<<'\n';
}
return 0;
}