Cod sursa(job #1853747)

Utilizator VictorAndreiCotescu Victor Andrei VictorAndrei Data 22 ianuarie 2017 00:23:31
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int a[100], n=6, s, p=0, m, b[100], k=0, ok=0;


    fstream f("loto.in");
    ofstream g("loto.out");

    f >> m >> s;

    for(int i=0; i<m; i++)
        f >> b[i];


    for (int i=0; i<n; i++)
        a[i]=b[0];



    for(int i = 0; i < n; i++)
    {
        k=1;

            if(p == s)
            {

            ok = 1;
            break;

            }


        for(int j = 0; j < m-1; j++)
        {

            a[i] = b[k];
            k++;


            for(int l = 0; l < n; l++)
            {
                p =  p+a[l];

            }

              if(p == s)
                 break;

            p = 0;

        }
    }




    for(int i = 0;i <= n-2 ;i++)
    for(int j = i+1;j <= n-1;j++)
    {
        if(a[i] > a[j])
        {
            swap(a[i], a[j]);
        }
    }

            if(ok == 1)
            {
            for(int x = 0; x < n ; x++)
                    g << a[x] << " ";
            }

            if(ok == 0)
                g << -1;




}