Pagini recente » Cod sursa (job #1653918) | Cod sursa (job #1459482) | Cod sursa (job #1115875) | Cod sursa (job #1826333) | Cod sursa (job #1573290)
#include <fstream>
#include <map>
#include <tuple>
using namespace std;
struct triplet
{
int a, b, c;
triplet(int x, int y, int z)
{
a = x;
b = y;
c = z;
}
};
int main()
{
int N, S, V[102], i, j, k, tmpSum;
map<int, triplet> m;
ifstream f("loto.in");
f >> N >> S;
for (i = 1; i <= N; i++)
{
f >> V[i];
}
f.close();
for (i = 1; i <= N; i++)
{
for (j = 1; j <= N; j++)
{
for (k = 1; k <= N; k++)
{
tmpSum = V[i] + V[j] + V[k];
//tuple<int, int, int> t(i, j, k);
triplet t(i, j, k);
m.insert(pair<int, triplet>(tmpSum, t));
}
}
}
ofstream g("loto.out");
for (i = 1; i <= N; i++)
{
for (j = 1; j <= N; j++)
{
for (k = 1; k <= N; k++)
{
tmpSum = V[i] + V[j] + V[k];
try
{
triplet t = m.at(S - tmpSum);
g << V[i] << " " << V[j] << " " << V[k] << " " << V[t.a] << " " << V[t.b] << " " << V[t.c] << flush;
return 0;
}
catch (const out_of_range &oor)
{
//continue;
}
}
}
}
g << -1;
g.close();
return 0;
}