Cod sursa(job #1344342)

Utilizator m1hm1nm1h m1n m1hm1n Data 16 februarie 2015 17:33:26
Problema Loto Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>

using namespace std;

int main()
{
    ifstream in("loto.in");
    int n; long s;
    in >> n >> s;
    long v[n];
    for(int i=0; i<n; i++){
        in >> v[i];
    }

   /* //Sortare vector
    long aux;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n-1; j++){
            if(v[i] < v[j]){
                aux = v[i];
                v[i] = v[j];
                v[j] = aux;
            }
        }
    }*/

    for(int a=n-1; a>=0; a--)
    {
        for(int b=n-1; b>=0; b--){
            for(int c=n-1; c>=0; c--){
                for(int d=n-1; d>=0; d--){
                    for(int e=n-1; e>=0; e--){
                        for(int f=n-1; f>=0; f--){
                            if(v[a]+v[b]+v[c]+v[d]+v[e]+v[f] == s){
                                ofstream out("loto.out");
                                out << v[a] << " " << v[b] << " " << v[c] << " " << v[d] << " " << v[e] << " " << v[f];
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }
    ofstream out("loto.out");
    out << -1;
}