Pagini recente » Cod sursa (job #159784) | Cod sursa (job #2066006) | Cod sursa (job #1030642) | Cod sursa (job #1761059) | Cod sursa (job #2744620)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define PRIM 7213
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n,val,operatie,viz[10000];
vector<int>::iterator it;
vector<vector<int>> h;
int hash_func(int cheie){
return cheie%PRIM;
}
void push(int x){
if(viz[x] == 0){
return;
}
int poz = hash_func(x);
h[poz].push_back(x);
}
void pop(int x){
int poz = hash_func(x);
for(it=h[poz].begin(); it!=h[poz].end(); it++){
if(*it == x){
*it = *(h[poz].end());
h[poz].pop_back();
return;
}
}
}
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;
}
int main()
{
f>>n;
for(int i=0;i<n;i++){
f>>operatie>>val;
if(operatie == 1) push(val);
if(operatie == 2) pop(val);
if(operatie == 3){
int poz = index(val);
g<<poz;
}
}
return 0;
}