Cod sursa(job #2742247)

Utilizator ChelaruPaulChelaru Paul ChelaruPaul Data 20 aprilie 2021 17:07:20
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

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

struct pereche {
    int x, y, z;
};

unordered_map<int, pereche> myHash;
int nrNr, suma, numere[101];

int main() {
    fin >> nrNr >> suma;
    for (int i = 0; i < nrNr; i++)
        fin >> numere[i];

    for (int i = 0; i < nrNr; i++)
        for (int j = i; j < nrNr; j++)
            for (int k = j; k < nrNr; k++){
                pereche pereche;
                pereche.x = numere[i];
                pereche.y = numere[j];
                pereche.z = numere[k];
                int s = pereche.x + pereche.y + pereche.z;
                myHash[s] = pereche;
            }
    
    int ok = 0;
    for(auto i = myHash.begin(); i != myHash.end() and ok == 0; i ++){
        int rest = suma - i->first;
        if(myHash.find(rest) != myHash.end()){
            fout << i->second.x << " " << i->second.y << " " << i->second.z <<
                 " " << myHash[rest].x << " " << myHash[rest].y << " " << myHash[rest].z;
            ok = 1;
        }
    }

    if(ok == 0) fout << -1;

}