Pagini recente » Cod sursa (job #1713844) | Cod sursa (job #74370) | Cod sursa (job #793409) | Cod sursa (job #1258708) | Cod sursa (job #2744747)
#include<iostream>
#include<fstream>
#include<unordered_map>
using namespace std;
ifstream cit("loto.in");
ofstream afis("loto.out");
struct Num{
int x, y, z;
};
unordered_map <int, Num> hesh;
bool ok = 0;
int main()
{
int N, S, nr[101], sum;
cit>>N>>S;
for(int i = 0; i < N; i++){
cit>>nr[i];
}
for(int i = 0; i < N; i++){
for(int j = i; j < N; j++){
for(int k = j; k < N; k++){
sum = nr[i] + nr[j] + nr[k];
if(hesh.find(S - sum) != hesh.end()){
afis<<nr[i]<<" "<<nr[j]<<" "<<nr[k]<<" ";
afis<<hesh[S-sum].x<<" "<<hesh[S-sum].y<<" "<<hesh[S-sum].z;
ok = 1;
i = j = k = N + 1;
}
else
{
Num tup;
tup.x = nr[i];
tup.y = nr[j];
tup.z = nr[k];
hesh[sum] = tup;
}
}
}
}
if(!ok){
afis<<-1;
}
return 0;
}