Cod sursa(job #2747864)

Utilizator mihaaelaMihaela Radu mihaaela Data 29 aprilie 2021 18:18:04
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

struct valori
{
    int a, b, c;
};

unordered_map <int, valori> hhash;

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

    int v[101], n, s, ok = 0;
    in >> n >> s;
    for(int i = 0; i < n; i++)
        in >> v[i];

                                                                //mapam valorile date (realizam sumele posibile)
    for(int i = 0; i < n; i++)
        for(int j = i; j < n; j++)
            for(int k = j; k < n; k++)
                hhash[v[i] + v[j] + v[k]] = {v[i], v[j], v[k]};

                                                                 //parcurgem map-ul
    for(auto i: hhash)
        if(hhash.find(s-i.first) != hhash.end())                  //in cazul in care gasim perechea lui s-i o afisam si ne oprim
        {
            cout << hhash[s-i.first].a << " " << hhash[s-i.first].b << " " << hhash[s-i.first].c << " " << i.second.a << " " << i.second.b << " " << i.second.c;
            ok = 1;
            break;                                               //cand am gasit o varianta ne oprim
        }
    if(!ok)                                                     //daca nu gasim nicio varianta afisam -1
        out << "-1";
    return 0;
}