Pagini recente » Cod sursa (job #2393524) | Cod sursa (job #1737873) | Cod sursa (job #2885267) | Cod sursa (job #1858301) | Cod sursa (job #1573362)
#include <fstream>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct triplet
{
int a, b, c;
triplet(int x, int y, int z)
{
a = x;
b = y;
c = z;
}
triplet()
{
a = b = c = 0;
}
};
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int N, S, V[102], i, j, k, tmpSum;
unordered_map<int, triplet> m;
ifstream f("loto.in");
f >> N >> S;
for (i = 1; i <= N; i++)
{
f >> V[i];
}
f.close();
sort(begin(V) + 1, begin(V) + N + 1);
for (i = 1; i <= N; i++)
{
for (j = i; j <= N; j++)
{
for (k = j; k <= N; k++)
{
tmpSum = V[i] + V[j] + V[k];
triplet t(i, j, k);
m[tmpSum] = t;
}
}
}
ofstream g("loto.out");
for (i = 1; i <= N; i++)
{
for (j = i; j <= N; j++)
{
for (k = j; k <= N; k++)
{
tmpSum = S - (V[i] + V[j] + V[k]);
triplet t = m[tmpSum];
if (t.a)
{
g << V[i] << " " << V[j] << " " << V[k] << " " << V[t.a] << " " << V[t.b] << " " << V[t.c];
return 0;
}
}
}
}
g << -1;
g.close();
return 0;
}