Pagini recente » Cod sursa (job #1088347) | Cod sursa (job #22811) | Cod sursa (job #223261) | Cod sursa (job #69674) | Cod sursa (job #2745323)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n, x, op;
vector<int> has[1000];
int hashh(int x){
return x%1009;
}
bool semafor(int x){
int ind = hashh(x);
for(int i=0;i<has[ind].size();i++){
if(has[ind][i] == x) return 1; // afisez 1 daca e in hash
}
return 0; //0 daca nu
}
void push(int x){
int ind;
if(!semafor(x)){
ind = hashh(x);
has[ind].push_back(x); // adaug x
}
}
void pop(int x){
int ind = hashh(x);
for(int i=0;i<has[ind].size();i++){
if(has[ind][i]==x)
{
has[ind].erase(has[ind].begin()+i); // sterg x
return;
}
}
}
int main()
{
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<<semafor(x)<<endl; // pe varianta 3 afisez
}
}
return 0;
}