Pagini recente » Cod sursa (job #2333189) | Cod sursa (job #2772486) | Cod sursa (job #1885729) | Cod sursa (job #495732) | Cod sursa (job #2745329)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> h[1000];
bool semaf(int x){
int poz = x%991;
for(int i=0;i<h[poz].size();i++){
if(h[poz][i] == x) return true; // 1 daca se gaseste
}
return false; //0 daca nu
}
void push(int x){
if(!semaf(x)){
h[x%991].push_back(x); // daca nu e in hash deja, il adaug
}
}
void pop(int x){
int poz = x%991;
for(int i=0;i<h[poz].size();i++){
if(h[poz][i]==x){
h[poz].erase(h[poz].begin()+i);// il sterg pe x din hash
return;
}
}
}
int main()
{
int n, x, op;
f>>n;
for(int i=0; i<n; i++)
{
f>>op>>x; // citesc fiecare pereche (operatie, numar)
if(op == 1)
push(x); // 1 => adaug cu push
else
{
if(op == 2)
pop(x); // 2 => sterg cu pop
else
g<<semaf(x)<<endl; // pe varianta 3 afisez
}
}
return 0;
}