Pagini recente » Cod sursa (job #523657) | Cod sursa (job #2808525) | Cod sursa (job #1427877) | Cod sursa (job #2278626) | Cod sursa (job #1879093)
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct key
{
unsigned int a, b, c;
};
map<unsigned int, key> answer;
vector<unsigned int> numbers;
int main()
{
unsigned int lottoNumbers = 0, sum = 0;
fin >> lottoNumbers >> sum;
for (unsigned int i = 0; i < lottoNumbers; i++)
{
unsigned int x = 0;
fin >> x;
numbers.push_back(x);
}
for (unsigned int i = 0; i < lottoNumbers; i++)
{
for (unsigned int j = 0; j < lottoNumbers; j++)
{
for (unsigned int k = 0; k < lottoNumbers; k++)
{
answer[numbers[i] + numbers[j] + numbers[k]] = key{ numbers[i] ,numbers[j],numbers[k] };
}
}
}
for (auto x : answer)
{
auto it = answer.find(sum - x.first);
if (it != answer.end())
{
fout << x.second.a << ' ' << x.second.b << ' ' << x.second.c << ' ' << it->second.a << ' ' << it->second.b << ' ' << it->second.c;
return 0;
}
}
fout << -1;
return 0;
}