Cod sursa(job #42980)

Utilizator the_dragon_of_rockTzogorean Alex the_dragon_of_rock Data 29 martie 2007 18:12:35
Problema Loto Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include<fstream>
using namespace std;
int a[200],n,x[10],s,gata=0,ss;

void back(int k)
{
    int i;
    for (i=1;i<=n && !gata;i++)
        {
            x[k]=i;
            ss=ss+a[x[k]];
            if (ss<=s)
                if (k==6)
                    if (ss==s)
                        gata=1;
                    else;
                else
                    back(k+1);
            ss=ss-a[x[k]];
        }
}

int main()
{
    ifstream in("loto.in");
    in>>n>>s;
    int i;
    for (i=1;i<=n;i++)
        in>>a[i];
    in.close();
    
    back(1);
    
    ofstream out("loto.out");
    if (gata==0)
        out<<-1;
    else
        for (i=1;i<=6;i++)
            out<<a[x[i]]<<" ";
    out.close();

    return 0;
}