Pagini recente » Cod sursa (job #1625254) | Cod sursa (job #3224661) | Cod sursa (job #1178680) | Cod sursa (job #2810472) | Cod sursa (job #2745302)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> hashh[1000];
int n, op, x;
bool semafor(int x){
int poz = x%271;
for(int i=0;i<hashh[poz].size();i++){
if(hashh[poz][i] == x) return true; // daca x se gaseste in hash, returnam true
}
return false; // daca nu, false
}
void push(int x){
if(semafor(x)!=0){
hashh[x%271].push_back(x); // adaugam x-ul in hash
}
}
void pop(int x){
int poz = x%271;
for(int i=0;i<hashh[poz].size();i++){
if(hashh[poz][i]==x){
hashh[poz].erase(hashh[poz].begin()+i); // stergem x-ul din hash
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;
}