Cod sursa(job #2055938)

Utilizator Tudor007Pricop Tudor Tudor007 Data 3 noiembrie 2017 22:28:56
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <iostream>
#include <fstream>

using namespace std;

long suma(int b[])
{
    long 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],ok=1;
    for(int i=0;i<6;i++)
        b[i]=1;
    while(suma(b)<S&&ok)
    {
        if(b[5]==N)
            ok=0;
        else
        {
            for(int i=0;i<6;i++)
                b[i]++;
        }
    }
    int i=5;
    while(suma(b)!=S)
    {
        b[i]--;
        i--;
    }





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


    return 0;

}