Pagini recente » Cod sursa (job #2979498) | Cod sursa (job #1010902) | Cod sursa (job #277977) | Cod sursa (job #136599) | Cod sursa (job #3128563)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
ifstream f1("loto.in");
ofstream f2("loto.out");
int N, S;
f1 >> N >> S;
vector<int> numbers(N);
for (int i = 0; i < N; i++)
f1 >> numbers[i];
bool found = false;
for (int a = 0; a < N && !found; a++)
{
for (int b = 0; b < N && !found; b++)
{
for (int c = 0; c < N && !found; c++)
{
for (int d = 0; d < N && !found; d++)
{
for (int e = 0; e < N && !found; e++)
{
for (int f = 0; f < N && !found; f++)
{
int sum = numbers[a] + numbers[b] + numbers[c] + numbers[d] + numbers[e] + numbers[f];
if (sum == S)
{
found = true;
f2 << numbers[a] << " " << numbers[b] << " " << numbers[c] << " "
<< numbers[d] << " " << numbers[e] << " " << numbers[f];
}
}
}
}
}
}
}
if (!found)
f2 << "-1";
f1.close();
f2.close();
return 0;
}