Cod sursa(job #3130694)

Utilizator Matoka26Dogaru Mihail Danut Matoka26 Data 18 mai 2023 14:02:23
Problema Loto Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");

struct trio{
    int primu;
    int doilea;
    int treilea;
};


int main(){
    unordered_map<int,trio> tabel;
    int n,sum,check = 0;
    fin>>n>>sum;
    int numere[n];
    for(int i = 0 ; i < n ; i++)
        fin>>numere[i];

    for(int i = 0 ; i < n && !check; i++)
        for(int j = 0 ; j < n && !check; j++)
            for(int k = 0 ; k < n && !check; k++){
                int suma = numere[i] + numere[j] + numere[k];
                tabel[suma] = {numere[i],numere[j],numere[k]};
                if(tabel.find(sum - suma) != tabel.end()){
                        check = 1;
                        fout<<tabel[sum-suma].primu<<" "<<tabel[sum-suma].doilea<<" "<<tabel[sum-suma].treilea<<" "<<numere[i]<<" "<<numere[j]<<" "<<numere[k];

                }
            }


    if(!check)
        fout<<-1;
fin.close();
fout.close();
return 0;
}