Cod sursa(job #2744455)

Utilizator LacatusLacatus Catalin-Petru Lacatus Data 24 aprilie 2021 18:39:07
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb

#include <fstream>
#include <unordered_map>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct numere
{
    int nr1,nr2,nr3;
};
unordered_map <int, numere> h;
int main()
{
    int n,s;
    f>>n>>s;
    int v[100];
    for(int i=0;i<n;i++)
        f>>v[i];

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

                numere obiect;
                obiect.nr1=v[i];
                obiect.nr2=v[j];
                obiect.nr3=v[k];
                h[v[i]+v[j]+v[k]]=obiect;

    }

    for(auto i=h.begin(); i!=h.end();i++)
    {
        int rest=s-i->first;
        if(h.find(rest)!=h.end())
        {
            g<<i->second.nr1<<' '<<i->second.nr2<<' '<<i->second.nr3<<' '<<h[rest].nr1<<' '<<h[rest].nr2<<' '<<h[rest].nr3;
            return 0;
        }
    }
    g<<"-1";
    return 0;
}