Cod sursa(job #2894864)

Utilizator Valentin06Maftei Valentin Valentin06 Data 28 aprilie 2022 15:13:07
Problema Loto Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");

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

unordered_map <int, perechi> loterie;
int nrLoterie, Suma, v[101], ok = 0;

int main() {
    in >> nrLoterie >> Suma;
    for (int i = 0; i < nrLoterie; i++)
        in >> v[i];
    for (int i = 0; i < nrLoterie; i++)
        for (int j = i; j < nrLoterie;j ++)
            for (int k = j; k < nrLoterie; k++)
            {
                perechi numar;
                numar.x = v[i];
                numar.y = v[j];
                numar.z = v[k];
                loterie.insert(make_pair(v[i] + v[j] + v[k], numar));
            }
    for (int i = 0; i < nrLoterie; i++)
        for (int j = i; j < nrLoterie; j++)
            for (int k = j; k < nrLoterie; k++)
                if (loterie.find(Suma - (v[i] + v[j] + v[k])) != loterie.end())
                {
                    out << loterie[Suma - v[i] - v[j] - v[k]].x << " " << loterie[Suma - v[i] - v[j] - v[k]].y << " " << loterie[Suma - v[i] - v[j] - v[k]].z << " " <<
                    loterie[Suma - v[i] - v[j] - v[k]].x << " " << loterie[Suma - v[i] - v[j] - v[k]].y << " " << loterie[Suma - v[i] - v[j] - v[k]].z;
                }
    return 0;
}