Pagini recente » Cod sursa (job #2336563) | Cod sursa (job #846385) | Cod sursa (job #1919702) | Cod sursa (job #37527) | Cod sursa (job #2894112)
#include <fstream>
#include<unordered_map>
#include <iostream>
using namespace std;
int n, suma;
int main()
{
std::ifstream fileIn("loto.in");
std::ofstream fileOut("loto.out");
int v[105];
unordered_map<int, std::pair<short,short>> multime1;
unordered_map<int, std::tuple<short,short,short>> multime;
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++) {
multime1.insert(std::make_pair<int, std::pair<short,short>>((v[i]+v[j]), std::make_pair<short,short>(i,j)));
}
}
unordered_map<int, std::pair<short,short>> ::iterator it;
for (it=multime1.begin(); it!=multime1.end(); ++it) {
for ( int j = 0; j < n; j++) {
std::tuple<short,short,short> tuplu ((*it).second.first,(*it).second.second,j);
std::pair<int, std::tuple<short,short,short>>perechea (((*it).first + v[j]), tuplu);
multime.insert(perechea);
}
}
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;
}