Pagini recente » Cod sursa (job #833204) | Cod sursa (job #1100998) | Cod sursa (job #2756215) | Cod sursa (job #240523) | Cod sursa (job #2773667)
#include <iostream>
#include <fstream>
#include <unordered_set>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
unordered_set <int> hashMap;
int n, suma;
int numere[101];
void afisareSuma(int suma){
for(int i = 1;i<=n;++i)
for(int j = 1;j<=n;++j)
for(int l = 1;l<=n;++l){
if(numere[i] + numere[j] + numere[l] == suma){
fout << numere[i] << " " << numere[j] << " " << numere[l]<<" ";
return;
}
}
}
int main()
{
fin>>n>>suma;
for(int i = 1;i<=n;++i){
fin>>numere[i];
}
for(int i = 1;i<=n;++i)
for(int j = 1;j<=n;++j)
for(int l = 1;l<=n;++l){
hashMap.insert(numere[i] + numere[j] + numere[l]);
}
for (const auto& elem: hashMap) {
if(!(hashMap.find(suma - elem) == hashMap.end())){
afisareSuma(elem);
afisareSuma(suma - elem);
return 0;
}
}
fout<<-1;
return 0;
}