Cod sursa(job #2894126)

Utilizator iulia.talpalariuIulia-Georgiana Talpalariu iulia.talpalariu Data 27 aprilie 2022 13:29:09
Problema Loto Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.15 kb
#include <fstream>
#include<unordered_map>


int main()
{
    std::ifstream fileIn("loto.in");
    std::ofstream fileOut("loto.out");
    int v[105];
    std::unordered_map<int, std::tuple<short,short,short>> multime;
    int n, suma;
    int x;
    fileIn >> n >> suma;


    for (int i = 0; i < n ; i++) {

        fileIn >> x;
        v[i] = x;

    }



   for(int i= 0; i < n; i++) {
        for ( int j = 0; j < n; j++)
            for (int k = 0; k< n; k++) {
            std::tuple<short,short,short> tuplu (i,j,k);
            std::pair<int, std::tuple<short,short,short>>perechea ((v[i] + v[j]+ v[k]), tuplu);


            if (multime.find(suma-(v[i] + v[j]+ v[k]))!= multime.end()) {
                std::tuple<short,short,short> tuplu2;
                tuplu2 = (*multime.find(suma-(v[i] + v[j]+ v[k]))).second;

                fileOut << v[std::get<0>(tuplu2)] << ' ';
                fileOut << v[std::get<1>(tuplu2)]<< ' ';
                fileOut << v[std::get<2>(tuplu2)]<< ' ';

                fileOut << v[std::get<0>(tuplu)] << ' ';
                fileOut << v[std::get<1>(tuplu)]<< ' ';
                fileOut << v[std::get<2>(tuplu)]<< ' ';

                return 0;


        } else {
            multime.insert(perechea);
        }

        }
    }

/*
    std::unordered_map <int, std::tuple<short,short,short>> ::iterator ptr;
    for (ptr=multime.begin(); ptr!=multime.end(); ++ptr) {

        if (multime.find(suma-(*ptr).first)!= multime.end()) {
            std::tuple<short,short,short> tuplu1;
            std::tuple<short,short,short> tuplu2;
            tuplu1 = (*ptr).second;
            tuplu2 = (*multime.find(suma-(*ptr).first)).second;
            fileOut << v[std::get<0>(tuplu1)] << ' ';
            fileOut << v[std::get<1>(tuplu1)]<< ' ';
            fileOut << v[std::get<2>(tuplu1)]<< ' ';

            fileOut << v[std::get<0>(tuplu2)] << ' ';
            fileOut << v[std::get<1>(tuplu2)]<< ' ';
            fileOut << v[std::get<2>(tuplu2)]<< ' ';
            break;
            exit(0);


        }
    }

*/
    fileOut << -1;

    return 0;

}