Pagini recente » Cod sursa (job #24707) | Cod sursa (job #2627265) | Cod sursa (job #550689) | Cod sursa (job #361500) | Cod sursa (job #363382)
Cod sursa(job #363382)
# include <fstream>
using namespace std;
ofstream fout ("loto.out");
struct nod {
int info;
nod *next;};
nod *p=NULL, *u=NULL;
int n, sum, a[105], x[8], pp;
void add (int x)
{
nod *t, *q;
if (p==NULL)
{
p=new nod;
p->info=x;
p->next=NULL;
u=p;
}
else
{
if (x>p->info)
{
t=new nod;
t->info=x;
t->next=p;
p=t;
}
else if (x<u->info)
{
t=new nod;
t->info=x;
t->next=NULL;
u->next=t;
u=t;
}
else
{
q=p;
while (q!=u && q->next->info>x) q=q->next;
t=new nod;
t->info=x;
t->next=q->next;
q->next=t;
}
}
}
void citire ()
{
int x, i;
ifstream fin ("loto.in");
fin>>n>>sum;
for (i=1;i<=n;i++)
{
fin>>x;
add(x);
}
i=0;
u=p;
while (u)
{
a[++i]=u->info;
u=u->next;
}
}
int afis ()
{
for (int i=1;i<=6;i++)
fout<<x[i]<<" ";
pp=1;
}
void bk (int k, int s)
{
for (int i=1;s+a[i]<=sum && i<=n && k<7 && pp==0;i++)
{
x[k]=a[i];
for (int j=1;j<=k;j++)
fout<<x[j]<<" ";
fout<<endl;
if (s+a[i]==sum && k==6)
afis ();
else
bk(k+1, s+a[i]);
}
}
int main ()
{
citire ();
bk (1, 0);
if (pp==0)
fout<<"-1";
return 0;
}