Pagini recente » Cod sursa (job #2663352) | Cod sursa (job #1178800) | Cod sursa (job #2305789) | Cod sursa (job #3286421) | Cod sursa (job #678077)
Cod sursa(job #678077)
#include <fstream>
#include <map>
#include <set>
using namespace std;
const char* infile = "loto.in";
const char* outfile = "loto.out";
struct SumaInfo
{
int a;
int b;
int c;
SumaInfo( int a, int b, int c)
{
this->a = a;
this->b = b;
this->c = c;
}
};
map<int , SumaInfo> Sume;
#define NMAX 101
int N;
int S;
int Nr[NMAX];
void CalcSume()
{
for(int i = 0 ; i < N; i++)
{
for (int j = 0; j < N; j++)
{
for (int k = 0; k < N ; k++)
{
Sume.insert(make_pair(Nr[i] + Nr[j] + Nr[k], SumaInfo(Nr[i], Nr[j], Nr[k])));
}
}
}
bool done = false;
for (map<int, SumaInfo>::iterator itr = Sume.begin();
itr != Sume.end();
itr++)
{
int toSearch = S - itr->first;
map<int, SumaInfo>::iterator found;
found = Sume.find(toSearch);
if(found != Sume.end())
{
done = true;
fstream fout(outfile, ios::out);
fout << itr->second.a << " "
<< itr->second.b << " "
<< itr->second.c << " "
<< found->second.a << " "
<< found->second.b << " "
<< found->second.c << "\n";
fout.close();
}
}
if (!done)
{
fstream fout(outfile, ios::out);
fout << "-1\n";
fout.close();
}
}
int main()
{
fstream fin(infile, ios::in);
fin >> N >> S;
for (int i = 0; i < N ; i++)
{
fin >> Nr[i];
}
fin.close();
CalcSume();
}