Cod sursa(job #614763)

Utilizator florin_ddumitriu florin florin_d Data 7 octombrie 2011 17:19:18
Problema Loto Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <stdio.h>
#include <map>

struct tri
{
	int x, y, z;
	tri(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
};

using namespace std;

int main()
{
	int a[200];
	int n, s;
	FILE *fin = fopen("loto.in", "r");
	FILE *fout = fopen("loto.out", "w");

	map<int, tri> Map;

	fscanf(fin, "%d", &n);
	fscanf(fin, "%d", &s);
    
	printf("%d %d", n, s);

	for(int i = 1; i <= n; i++)
		fscanf(fin, "%d", &a[i]);
	

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			for(int k = 1; k <= n; k++)
			{
				int temp  = a[i] + a[j] + a[k];
				map<int, tri>::iterator it;
				
				if( (it = Map.find( s - temp ) ) != Map.end())
				{
					tri found = (*it).second;
					fprintf(fout, " %d %d %d %d %d %d", a[i], a[j], a[k], found.x, found.y, found.z);
					return 0;
				} else Map.insert(Map.begin(), pair<int, tri>( temp, tri( a[i], a[j], a[k] ) ) );

			}

    fprintf(fout, "%d", -1 );
	return 0;
}