Cod sursa(job #2895270)

Utilizator biancar28Radulescu Alexia-Bianca biancar28 Data 28 aprilie 2022 21:01:40
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <unordered_map>
#include <tuple>
#include <fstream>

using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");

int main() {

    int n,s,i,suma,dif,j,z,v[101];
    f>>n>>s;
    unordered_map<int, tuple<int,int,int>>M;

    for(i=0;i<n;i++)
    {
        f>>v[i];
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            for(z=0;z<n;z++)
            {
                suma = v[i]+v[j]+v[z];
                M[suma]=make_tuple(v[i],v[j],v[z]);
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            for(z=0;z<n;z++)
            {
                dif = s-v[i]-v[j]-v[z];
                if(M.find(dif) != M.end()){
                    g<<get<0>(M[dif])<<" "<<get<1>(M[dif])<<" "<<get<2>(M[dif])<<" ";
                    g<<v[i]<<" "<<v[j]<<" "<<v[z]<<" ";
                    return 0;
                }
            }
        }
    }
    g<<-1;

    g.close();
    f.close();

    return 0;
}