Cod sursa(job #678077)

Utilizator Cosmin1490Balan Radu Cosmin Cosmin1490 Data 10 februarie 2012 23:49:21
Problema Loto Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <fstream>
#include <map>
#include <set>
using namespace std;

const char* infile = "loto.in";
const char* outfile = "loto.out";


struct SumaInfo
{
	int a;
	int b;
	int c;
	SumaInfo( int a, int b, int c)
	{
		this->a = a;
		this->b = b;
		this->c = c;
	}
};

map<int , SumaInfo> Sume;

#define NMAX 101

int N;
int S;

int Nr[NMAX];


void CalcSume() 
{
	for(int i = 0 ; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			for (int k = 0; k < N ; k++)
			{
				Sume.insert(make_pair(Nr[i] + Nr[j] + Nr[k], SumaInfo(Nr[i], Nr[j], Nr[k])));
			}
		}
	}
	bool done = false;

	for (map<int, SumaInfo>::iterator itr = Sume.begin();
		 itr != Sume.end();
		 itr++)
	{
		int toSearch = S - itr->first;
		map<int, SumaInfo>::iterator found;
		found = Sume.find(toSearch);

		if(found != Sume.end())
		{
			done = true;
			fstream fout(outfile, ios::out);
			fout << itr->second.a << " "
				 << itr->second.b << " "
				 << itr->second.c << " "
				 << found->second.a << " "
				 << found->second.b << " "
				 << found->second.c << "\n";
			fout.close();
		}

	}

	if (!done)
	{
		fstream fout(outfile, ios::out);
		fout << "-1\n";
		fout.close();
	}
}

int main()
{
	fstream fin(infile, ios::in);

	fin >> N >> S;

	for (int i = 0; i < N ; i++)
	{
		fin >> Nr[i];
	}

	fin.close();
	
	CalcSume();

	

}