Pagini recente » Cod sursa (job #1149849) | Cod sursa (job #1993880) | Cod sursa (job #1944043) | Cod sursa (job #2019607) | Cod sursa (job #1318440)
#include <iostream>
#include <unordered_map>
#include <fstream>
using namespace std;
struct comb
{
int a, b, c;
};
unordered_map<int, comb> M;
int n, s, a[101];
int main()
{
ifstream f("loto.in");
ofstream g("loto.out");
f>>n>>s;
int i, j, k;
comb x;
for (i=1;i<=n;i++)
f>>a[i];
for (i=1;i<=n;i++)
for (j=i;j<=n;j++)
for (k=j;k<=n;k++)
{
x.a=a[i];
x.b=a[j];
x.c=a[k];
M.insert(make_pair(a[i]+a[j]+a[k], x));
}
unordered_map<int, comb>::iterator it, it2;
bool ok=false;
for (it=M.begin(); it!=M.end() && !ok; it++)
{
it2=M.find(s-it->first);
if (it2!=M.end())
{
g<<it->second.a<<' '<<it->second.b<<' '<<it->second.c<<' ';
g<<it2->second.a<<' '<<it2->second.b<<' '<<it2->second.c<<'\n';
ok=true;
}
}
if (ok==false) g<<"-1\n";
}