Pagini recente » Cod sursa (job #2572500) | Cod sursa (job #413562) | Cod sursa (job #3235631) | Cod sursa (job #3273951) | Cod sursa (job #2894126)
#include <fstream>
#include<unordered_map>
int main()
{
std::ifstream fileIn("loto.in");
std::ofstream fileOut("loto.out");
int v[105];
std::unordered_map<int, std::tuple<short,short,short>> multime;
int n, suma;
int x;
fileIn >> n >> suma;
for (int i = 0; i < n ; i++) {
fileIn >> x;
v[i] = x;
}
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);
if (multime.find(suma-(v[i] + v[j]+ v[k]))!= multime.end()) {
std::tuple<short,short,short> tuplu2;
tuplu2 = (*multime.find(suma-(v[i] + v[j]+ v[k]))).second;
fileOut << v[std::get<0>(tuplu2)] << ' ';
fileOut << v[std::get<1>(tuplu2)]<< ' ';
fileOut << v[std::get<2>(tuplu2)]<< ' ';
fileOut << v[std::get<0>(tuplu)] << ' ';
fileOut << v[std::get<1>(tuplu)]<< ' ';
fileOut << v[std::get<2>(tuplu)]<< ' ';
return 0;
} else {
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>(tuplu1)] << ' ';
fileOut << v[std::get<1>(tuplu1)]<< ' ';
fileOut << v[std::get<2>(tuplu1)]<< ' ';
fileOut << v[std::get<0>(tuplu2)] << ' ';
fileOut << v[std::get<1>(tuplu2)]<< ' ';
fileOut << v[std::get<2>(tuplu2)]<< ' ';
break;
exit(0);
}
}
*/
fileOut << -1;
return 0;
}