Cod sursa(job #3130738)

Utilizator FlaviaF7Fota Stefania-Flavia FlaviaF7 Data 18 mai 2023 14:57:11
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#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;
}