Cod sursa(job #3130537)

Utilizator Alexandra789Alexandra Uceanu Alexandra789 Data 17 mai 2023 22:25:34
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

int main(){
    std::ifstream f("loto.in");
    std::ofstream g("loto.out");

    int n, s, numere[100];
    f >> n >> s;
    for(int i = 0; i < n; i++)
        f >> numere[i];

    std::unordered_map<int, int[3]> hashTable;

    bool combinatie = 0;
    for(int i = 0; i < n && !combinatie; i++)
        for(int j = i; j < n && !combinatie; j++)
            for(int k = j; k < n && !combinatie; k++){
                hashTable[numere[i] + numere[j] + numere[k]][0] = numere[i];
                hashTable[numere[i] + numere[j] + numere[k]][1] = numere[j];
                hashTable[numere[i] + numere[j] + numere[k]][2] = numere[k];

                int dif = s - numere[i] - numere[j] - numere[k];
                if(hashTable.find(dif) != hashTable.end()){
                    combinatie = 1;
                    g << numere[i] << ' ' << numere[j] << ' ' << numere[k] << ' ' << hashTable[dif][0] << ' ' <<
                        hashTable[dif][1] << ' ' << hashTable[dif][2] << '\n';
                }
            }  

    if(!combinatie)
        g << -1;
    return 0;
}