Cod sursa(job #3128563)

Utilizator Alexco2003Codarcea Alexandru-Christian Alexco2003 Data 9 mai 2023 21:59:47
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.36 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
    ifstream f1("loto.in");
    ofstream f2("loto.out");

    int N, S;
    f1 >> N >> S;

    vector<int> numbers(N);
    for (int i = 0; i < N; i++)
        f1 >> numbers[i];

    bool found = false;
    for (int a = 0; a < N && !found; a++)
    {
        for (int b = 0; b < N && !found; b++)
        {
            for (int c = 0; c < N && !found; c++)
            {
                for (int d = 0; d < N && !found; d++)
                {
                    for (int e = 0; e < N && !found; e++)
                    {
                        for (int f = 0; f < N && !found; f++)
                        {
                            int sum = numbers[a] + numbers[b] + numbers[c] + numbers[d] + numbers[e] + numbers[f];
                            if (sum == S)
                            {
                                found = true;
                                f2 << numbers[a] << " " << numbers[b] << " " << numbers[c] << " "
                                   << numbers[d] << " " << numbers[e] << " " << numbers[f];
                            }
                        }
                    }
                }
            }
        }
    }

    if (!found)
        f2 << "-1";

    f1.close();
    f2.close();

    return 0;
}