Pagini recente » Cod sursa (job #849236) | Cod sursa (job #1285047) | Cod sursa (job #2553396) | Cod sursa (job #557521) | Cod sursa (job #2895443)
#include <fstream>
#include<unordered_map>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct numere {
int i, j, k;
};
unordered_map <int, numere> solutie;
int main()
{
int nrNumere, sumaNumerelor;
fin >> nrNumere >> sumaNumerelor;
int* nrLoteriaNationala;
nrLoteriaNationala = new int[nrNumere];
for (int i = 1; i <= nrNumere; i++)
fin >> nrLoteriaNationala[i];
int sumaCurenta = 0;
for(int i = 1; i <= nrNumere; i++)
for(int j = i; j <= nrNumere; j++)
for (int k = j; k <= nrNumere; k++)
{
numere bilet;
bilet.i = nrLoteriaNationala[i];
bilet.j = nrLoteriaNationala[j];
bilet.k = nrLoteriaNationala[k];
sumaCurenta = bilet.i + bilet.j + bilet.k;
solutie[sumaCurenta] = bilet;
}
int gasitSolutie = 0;
for(int i = 1; i <= nrNumere && !gasitSolutie; i++)
for (int j = i; j <= nrNumere && !gasitSolutie; j++)
for (int k = j; k <= nrNumere && !gasitSolutie; k++)
{
numere bilet;
bilet.i = nrLoteriaNationala[i];
bilet.j = nrLoteriaNationala[j];
bilet.k = nrLoteriaNationala[k];
int dif = sumaNumerelor - (bilet.i + bilet.j + bilet.k);
if (solutie.find(dif) != solutie.end())
{
fout << bilet.i << " " << bilet.j << " " << bilet.k << " " << solutie[dif].i << " " << solutie[dif].j << " " << solutie[dif].k;
gasitSolutie = 1;
}
}
if (gasitSolutie == 0)
fout << "-1";
}