Pagini recente » Cod sursa (job #934876) | Cod sursa (job #1753691) | Cod sursa (job #2271672) | Cod sursa (job #2476664) | Cod sursa (job #2747864)
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
struct valori
{
int a, b, c;
};
unordered_map <int, valori> hhash;
int main()
{
ifstream in("loto.in");
ofstream out("loto.out");
int v[101], n, s, ok = 0;
in >> n >> s;
for(int i = 0; i < n; i++)
in >> v[i];
//mapam valorile date (realizam sumele posibile)
for(int i = 0; i < n; i++)
for(int j = i; j < n; j++)
for(int k = j; k < n; k++)
hhash[v[i] + v[j] + v[k]] = {v[i], v[j], v[k]};
//parcurgem map-ul
for(auto i: hhash)
if(hhash.find(s-i.first) != hhash.end()) //in cazul in care gasim perechea lui s-i o afisam si ne oprim
{
cout << hhash[s-i.first].a << " " << hhash[s-i.first].b << " " << hhash[s-i.first].c << " " << i.second.a << " " << i.second.b << " " << i.second.c;
ok = 1;
break; //cand am gasit o varianta ne oprim
}
if(!ok) //daca nu gasim nicio varianta afisam -1
out << "-1";
return 0;
}