Pagini recente » Cod sursa (job #268665) | Cod sursa (job #2483641) | Cod sursa (job #753017) | Cod sursa (job #2661772) | Cod sursa (job #614768)
Cod sursa(job #614768)
#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;
}