Cod sursa(job #1879093)

Utilizator loghin.alexandruLoghin Alexandru loghin.alexandru Data 14 februarie 2017 18:31:21
Problema Loto Scor 75
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#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;
}