Pagini recente » Cod sursa (job #3180814) | Cod sursa (job #1410152) | Cod sursa (job #2287483) | Cod sursa (job #2626535) | Cod sursa (job #3130537)
#include <iostream>
#include <fstream>
#include <unordered_map>
int main(){
std::ifstream f("loto.in");
std::ofstream g("loto.out");
int n, s, numere[100];
f >> n >> s;
for(int i = 0; i < n; i++)
f >> numere[i];
std::unordered_map<int, int[3]> hashTable;
bool combinatie = 0;
for(int i = 0; i < n && !combinatie; i++)
for(int j = i; j < n && !combinatie; j++)
for(int k = j; k < n && !combinatie; k++){
hashTable[numere[i] + numere[j] + numere[k]][0] = numere[i];
hashTable[numere[i] + numere[j] + numere[k]][1] = numere[j];
hashTable[numere[i] + numere[j] + numere[k]][2] = numere[k];
int dif = s - numere[i] - numere[j] - numere[k];
if(hashTable.find(dif) != hashTable.end()){
combinatie = 1;
g << numere[i] << ' ' << numere[j] << ' ' << numere[k] << ' ' << hashTable[dif][0] << ' ' <<
hashTable[dif][1] << ' ' << hashTable[dif][2] << '\n';
}
}
if(!combinatie)
g << -1;
return 0;
}