Cod sursa(job #2038590)

Utilizator LucaSeriSeritan Luca LucaSeri Data 13 octombrie 2017 20:27:57
Problema Loto Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <map>
using namespace std;

int v[101];

ifstream f("loto.in");
ofstream g("loto.out");
struct nr{int a, b, c;};
map<int, nr> sume;
int main(){
    int n, s;
    f >> n >> s;
    for(int i = 0; i < n; ++i){
        f >> v[i];
    }
    for(int i = 0; i < n; ++ i){
        for(int j = 0; j < n; ++ j){
            for(int k = 0; k < n; ++k){
                int sum = v[i] + v[j] + v[k];
                nr aux;
                aux.a = v[i]; aux.b = v[j]; aux.c = v[k];
                sume[sum] = aux;
                if(sume.find(s-sum) != sume.end()){
                    nr temp = sume[s-sum];
                    g << v[i] << ' ' << v[j] << ' ' << v[k] << ' ' << temp.a << ' ' << temp.b << ' ' << temp.c;
                    return 0;
                }
            }
        }
    }

    g << -1;
    return 0;
}