Pagini recente » Cod sursa (job #1139186) | Cod sursa (job #2345727) | Cod sursa (job #1163065) | Cod sursa (job #2422667) | Cod sursa (job #1394115)
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
//az n meximalis erteke
const unsigned short MaxN=100, LottoNr=6;
typedef struct
{
unsigned long x[3];
} state;
typedef map <unsigned long, state> num_map;
num_map mp; //eltaroljuk azt is hogy hanyadik volt az elozo
unsigned long a[MaxN], s;
unsigned short n;
state gen_state(unsigned long x0, unsigned long x1, unsigned long x2)
{
state tst;
tst.x[0]=x0;
tst.x[1]=x1;
tst.x[2]=x2;
return tst;
}
int main(void)
{
ifstream fi("loto.in", ios::in);
ofstream fo("loto.out", ios::out);
unsigned short i, j, k, l;
num_map::iterator it, it2;
bool won=false;
fi>>n>>s;
for (i=0; i!=n; i++)
fi>>a[i];
for (i=0; i!=n; i++)
for (j=0; j!=n; j++)
for (k=0; k!=n; k++)
mp[a[i]+a[j]+a[k]]=gen_state(a[i], a[j], a[k]);
for (it=mp.begin(); (it!=mp.end())&&(!won); it++)
{
if ((it2=mp.find(s-(it->first))) !=mp.end())
{
won=true; //megvan a nyero kombinacio
for (l=0; l!=3; l++)
{
fo<<(it->second.x[l]);
fo<<' ';
fo<<(it2->second.x[l]);
fo<<' ';
}
}
}
if (!won)
fo<<-1;
fo<<'\n';
fo.close();
fi.close();
return 0;
}