Pagini recente » Cod sursa (job #2116274) | Cod sursa (job #2493535) | Cod sursa (job #409785) | Cod sursa (job #1587275) | Cod sursa (job #2894138)
#include <fstream>
#include<unordered_map>
int main()
{
std::ifstream fileIn("loto.in");
std::ofstream fileOut("loto.out");
int v[100];
std::unordered_map<int, std::tuple<short,short,short>> multime;
short n;
int suma;
fileIn >> n >> suma;
for (int i = 0; i < n ; i++) {
fileIn >>v[i];
}
for(int i= 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++) {
std::tuple<short,short,short> tuplu (i,j,k);
std::pair<int, std::tuple<short,short,short>>perechea ((v[i] + v[j]+ v[k]), tuplu);
multime.insert(perechea);
}
std::unordered_map <int, std::tuple<short,short,short>> ::iterator ptr;
for (ptr=multime.begin(); ptr!=multime.end(); ++ptr) {
if (multime.find(suma-(*ptr).first)!= multime.end()) {
std::tuple<short,short,short> tuplu1;
std::tuple<short,short,short> tuplu2;
tuplu1 = (*ptr).second;
tuplu2 = (*multime.find(suma-(*ptr).first)).second;
fileOut << v[std::get<0>(tuplu2)] << ' ';
fileOut << v[std::get<1>(tuplu2)]<< ' ';
fileOut << v[std::get<2>(tuplu2)]<< ' ';
fileOut << v[std::get<0>(tuplu1)] << ' ';
fileOut << v[std::get<1>(tuplu1)]<< ' ';
fileOut << v[std::get<2>(tuplu1)]<< ' ';
return 0;
}
}
fileOut << -1;
return 0;
}