Cod sursa(job #779922)

Utilizator fhandreiAndrei Hareza fhandrei Data 19 august 2012 01:43:29
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.27 kb
//Include
#include <fstream>
#include <set>
using namespace std;

//Structuri
struct mystr
{
	int value;
	int first, second, third;
}newElement;

//Clase
class compare
{
	public:
	bool operator() (mystr a, mystr b)
	{	return a.value < b.value;	}
};

//Variabile
ifstream in("loto.in");
ofstream out("loto.out");

int eNum, sum;
int numbers[101];

multiset<mystr, compare> sums;
multiset<mystr, compare>::iterator it1, it2, end;

//Main
int main()
{
	in >> eNum >> sum;
	for(int i=1 ; i<=eNum ; ++i)
		in >> numbers[i];
	
	for(int i=1 ; i<=eNum ; ++i)
		for(int j=1 ; j<=eNum ; ++j)
			for(int k=1 ; k<=eNum ; ++k)
			{
				newElement.value = numbers[i] + numbers[j] + numbers[k];
				newElement.first = numbers[i];
				newElement.second = numbers[j];
				newElement.third = numbers[k];
				sums.insert(newElement);
			}
	
	end = sums.end();
	
	for(it1=sums.begin() ; it1!=end ; ++it1)
		for(it2=it1, ++it2 ; it2!=end ; ++it2)
		{
			if(it1->value + it2->value == sum)
			{
				out << it1->first << ' ' << it1->second << ' ' << it1->third << ' ' << it2->first << ' ' << it2->second << ' ' << it2->third << '\n';
				in.close();
				out.close();
				return 0;
			}
		}
	
	
	out << -1 << '\n';
	in.close();
	out.close();
	return 0;
}