Cod sursa(job #717076)

Utilizator w3.playerCostescu Ionut w3.player Data 19 martie 2012 17:17:25
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <iostream>
using namespace std;
int n;
long s,v[100];

void read()
{
	int i;
	ifstream inFile("loto.in");
	inFile >> n >> s;
	for (i=0; i<n; i++)
		inFile >> v[i];
	inFile.close();
}

void fix_and_type()
{
	int i,j,k,l,m,o,r=0;
	sort(v,v+n);
	for(i=n-1; i>=0; i--)
		for(j=n-1; j>=0; j--)
			for(k=n-1; k>=0; k--)
				for(l=n-1; l>=0; l--)
					for(m=n-1; m>=0; m--)
						for(o=n-1; o>=0; o--)
							if (v[i]+v[j]+v[k]+v[l]+v[m]+v[o]==s)
							{
								ofstream outFile("loto.out");
								outFile << v[i] << " " << v[j] << " " << v[k] << " " << v[l] << " " << v[m] << " " << v[o] << "\n";
								outFile.close();
								r=1;
							}
	if (r==0)
	{
		ofstream outFile("loto.out");
		outFile << -1 << "\n";
		outFile.close();
	}
}

int main()
{
	read();
	fix_and_type();
	return 0;
}