Cod sursa(job #2895443)

Utilizator miruna_georgescuMiruna Georgescu miruna_georgescu Data 29 aprilie 2022 08:15:48
Problema Loto Scor 65
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.79 kb
#include <fstream>
#include<unordered_map>
using namespace std; 

ifstream fin("loto.in");
ofstream fout("loto.out");

struct numere {
    int i, j, k; 
};

unordered_map <int, numere> solutie; 

int main()
{
    int nrNumere, sumaNumerelor; 
    fin >> nrNumere >> sumaNumerelor;

    int* nrLoteriaNationala; 
    nrLoteriaNationala = new int[nrNumere]; 
    for (int i = 1; i <= nrNumere; i++)
        fin >> nrLoteriaNationala[i]; 

    int sumaCurenta = 0;
    for(int i = 1; i <= nrNumere; i++)
        for(int j = i; j <= nrNumere; j++)
            for (int k = j; k <= nrNumere; k++)
            {
                numere bilet; 
                bilet.i = nrLoteriaNationala[i]; 
                bilet.j = nrLoteriaNationala[j];
                bilet.k = nrLoteriaNationala[k];
                
                sumaCurenta = bilet.i + bilet.j + bilet.k; 
                solutie[sumaCurenta] = bilet; 
            }

    int gasitSolutie = 0; 
    for(int i = 1; i <= nrNumere && !gasitSolutie; i++)
        for (int j = i; j <= nrNumere && !gasitSolutie; j++)
            for (int k = j; k <= nrNumere && !gasitSolutie; k++)
            {
                numere bilet;
                bilet.i = nrLoteriaNationala[i];
                bilet.j = nrLoteriaNationala[j];
                bilet.k = nrLoteriaNationala[k];
                
                int dif = sumaNumerelor - (bilet.i + bilet.j + bilet.k); 
                
                if (solutie.find(dif) != solutie.end())
                {
                    fout << bilet.i << " " << bilet.j << " " << bilet.k << " " << solutie[dif].i << " " << solutie[dif].j << " " << solutie[dif].k; 
                    gasitSolutie = 1; 
                }

            }

    if (gasitSolutie == 0)
        fout << "-1"; 
}