Cod sursa(job #1879015)

Utilizator loghin.alexandruLoghin Alexandru loghin.alexandru Data 14 februarie 2017 17:49:33
Problema Loto Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

struct key
{
	unsigned int a, b, c;
};

unordered_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 (unsigned int i = 0; i < lottoNumbers; i++)
	{
		for (unsigned int j = 0; j < lottoNumbers; j++)
		{
			for (unsigned int k = 0; k < lottoNumbers; k++)
			{
				auto it = answer.find(sum - (numbers[i] + numbers[j] + numbers[k]));
				if (it != answer.end())
				{
					fout << it->second.a << ' ' << it->second.b << ' ' << it->second.c << ' ' << numbers[i] << ' ' << numbers[j] << ' ' << numbers[k];
					return 0;
				}
			}
		}
	}
	fout << -1;
	return 0;
}