Pagini recente » Cod sursa (job #370436) | Cod sursa (job #1457395) | Cod sursa (job #588423) | Cod sursa (job #1713404) | Cod sursa (job #2745445)
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
struct triple
{
int first, second, third;
};
unordered_map <int, triple> loto;
int numere[102];
int main() {
int n, s;
in >> n >> s;
int i, j, k;
for(i = 1; i <= n; i++)
{
in >> numere[i];
}
for(i = 1; i <= n; i++)
{
for(j = i; j <= n; j++)
{
for(k = j; k <= n; k++)
{
int sc = numere[i] + numere[j] + numere[k];
loto[sc].first = numere[i];
loto[sc].second = numere[j];
loto[sc].third = numere[k];
if(loto.find(s-sc) != loto.end())
{
out << numere[i] << " " << numere[j] << " " << numere[k] << " " << loto[s-sc].first << " " << loto[s-sc].second << " " << loto[s-sc].third;
return 0;
}
}
}
}
out << -1;
return 0;
}