Pagini recente » Cod sursa (job #2527136) | Cod sursa (job #1898609) | Cod sursa (job #67006) | Cod sursa (job #1517714) | Cod sursa (job #2742247)
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct pereche {
int x, y, z;
};
unordered_map<int, pereche> myHash;
int nrNr, suma, numere[101];
int main() {
fin >> nrNr >> suma;
for (int i = 0; i < nrNr; i++)
fin >> numere[i];
for (int i = 0; i < nrNr; i++)
for (int j = i; j < nrNr; j++)
for (int k = j; k < nrNr; k++){
pereche pereche;
pereche.x = numere[i];
pereche.y = numere[j];
pereche.z = numere[k];
int s = pereche.x + pereche.y + pereche.z;
myHash[s] = pereche;
}
int ok = 0;
for(auto i = myHash.begin(); i != myHash.end() and ok == 0; i ++){
int rest = suma - i->first;
if(myHash.find(rest) != myHash.end()){
fout << i->second.x << " " << i->second.y << " " << i->second.z <<
" " << myHash[rest].x << " " << myHash[rest].y << " " << myHash[rest].z;
ok = 1;
}
}
if(ok == 0) fout << -1;
}