Pagini recente » Cod sursa (job #1884214) | Istoria paginii utilizator/adela-marin | Cod sursa (job #2816341) | Cod sursa (job #371384) | Cod sursa (job #3130738)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in ("loto.in");
ofstream out ("loto.out");
void bilet_castigator(const vector<int>& numere, int suma, vector<int>& solutie, int& gasit){
if (suma == 0 && solutie.size() == 6) {
gasit = 1;
for (int numar : solutie) {
out << numar << " ";
}
return;
}
if (suma < 0 || solutie.size() >= 6 || gasit) {
return;
}
for (int numar : numere) {
solutie.push_back(numar);
bilet_castigator(numere, suma - numar, solutie, gasit);
solutie.pop_back();
}
}
int main(){
int n,s;
vector<int> v;
in >> n >> s;
for (int i=0; i<n; i++){
int nr;
in >> nr;
v.push_back(nr);
}
vector<int> solutie;
int gasit = 0;
bilet_castigator(v,s,solutie,gasit);
if (!gasit){
out << -1;
}
in.close();
out.close();
return 0;
}