Cod sursa(job #2842651)

Utilizator MateiB1230Matei B MateiB1230 Data 1 februarie 2022 11:54:15
Problema Loto Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>

using namespace std;
ifstream f("loto.in");
ofstream ga("loto.out");
unsigned int a[1009],st[1009],n,S,g;

int afisare()
{
   unsigned int i,s=0;
    for(i=1;i<=6;i++) s=s+a[st[i]];
    if(s==S)
    {
        for(i=1;i<=6;i++)
             ga<<a[st[i]]<<" ";
        ga<<endl;
        return 1;
    }
}

void bkt(int k)
{
    for(int i=1;i<=n&&g==0;i++)
    {
        st[k]=i;
        if (k<6) bkt(k+1);
        else if(afisare()==1) g=1;
    }

}

int main()
{
    int i=1,x;
f>>n>>S;
while(f>>x)
    a[i++]=x;
 bkt(1);
 if(g==0) ga<<-1;

}