Pagini recente » Cod sursa (job #592133) | Cod sursa (job #1004272) | Cod sursa (job #1833610) | Cod sursa (job #1324378) | Cod sursa (job #2744677)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n,operatie;
long x;
vector<long> h[10000];
int hash_func(int x){
return x%997;
}
int index(long x){
int poz = hash_func(x);
for(int i=0;i<h[poz].size();i++){
if(h[poz][i] == x){
h[poz][i] = 0;
return 1;
}
}
return 0;
}
void push(long x){
int poz = hash_func(x);
h[poz].push_back(x);
}
void pop(long x){
int poz = x%997;
for(int i=0;i<h[poz].size();i++){
if(h[poz][i] == x){
h[poz].erase(h[poz].begin() + i);
}
}
}
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;
}