Cod sursa(job #2055862)

Utilizator Tudor007Pricop Tudor Tudor007 Data 3 noiembrie 2017 20:41:34
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.8 kb
#include <iostream>
#include <fstream>

using namespace std;

void afisare(int n,int a[])
{
    for(int i=0;i<n;i++)
        cout << a[i] << " ";
}

int suma(int b[])
{
    int sum=0;
    for(int i=0;i<6;i++)
        sum+=b[i];
    return sum;
}

int main()
{
    int N;
    long S;
    int a[100];

    ifstream fin("loto.in");
    fin >> N >> S;
    for(int i=0;i<N;i++)
        fin >> a[i];
    fin.close();

    int b[6]={1,1,1,1,1,1},ok=1;


        int d=1;
        while(d<=a[N-1]&&ok)
        {
            b[0]=d;
            int e=1;
            while(e<=a[N-1]&&ok)
            {
                b[1]=e;
                int f=1;
                while(f<=a[N-1]&&ok)
                {
                    b[2]=f;
                    int g=1;
                    while(g<=a[N-1]&&ok)
                    {
                        b[3]=g;
                        int h=1;
                        while(h<=a[N-1]&&ok)
                        {
                            b[4]=h;
                            int i=1;
                            while(i<=a[N-1]&&ok)
                            {
                                b[5]=i;
                                if(suma(b)==S)
                                    ok=0;
                                i++;
                            }
                            h++;
                        }
                        g++;
                    }
                    f++;
                }
                e++;
            }
            d++;
        }

        ofstream fout("loto.out");
        if(ok==1)
        {
            fout << -1;
        }
        else
        {
            for(int i=0;i<6;i++)
            fout << b[i] << " ";
        }
        fout.close();


    return 0;

}