fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void print_max_5_prod(double input[16])
  5. {
  6. cout<<"The 5 numbers with max product are: ";
  7. if(input[15] < 0) // Step 1
  8. cout<<input[11]<<" "<<input[12]<<" "<<input[13]<<" "<<input[14]<<" "<<input[15]<<endl;
  9. else if (input[13] < 0) // Step 2
  10. cout<<input[1]<<" "<<input[2]<<" "<<input[3]<<" "<<input[4]<<" "<<input[15]<<endl;
  11. else
  12. {
  13. if(input[11] < 0)
  14. {
  15. double prod_1 = input[3]*input[4];
  16. double prod_2 = input[13]*input[14];
  17. if(prod_1 > prod_2)
  18. cout<<input[1]<<" "<<input[2]<<" "<<input[3]<<" "<<input[4]<<" "<<input[15]<<endl;
  19. else
  20. cout<<input[1]<<" "<<input[2]<<" "<<input[13]<<" "<<input[14]<<" "<<input[15]<<endl;
  21. }
  22. else
  23. {
  24. if((input[1]*input[2])>(input[11]*input[12]))
  25. {
  26. cout<<input[1]<<" "<<input[2]<<" ";
  27. if((input[3]*input[4])>(input[13]*input[14]))
  28. cout<<input[3]<<" "<<input[4]<<" "<<input[15]<<endl;
  29. else
  30. cout<<input[13]<<" "<<input[14]<<" "<<input[15]<<endl;
  31. }
  32. else
  33. cout<<input[11]<<" "<<input[12]<<" "<<input[13]<<" "<<input[14]<<" "<<input[15]<<endl;
  34.  
  35. }
  36. }
  37. }
  38.  
  39. int main() {
  40. double input[16]; // Let's make it 1-based index
  41. for(int i=1; i<=15; ++i)
  42. cin>>input[i];
  43. print_max_5_prod(input);
  44. return 0;
  45. }
Success #stdin #stdout 0s 4352KB
stdin
 -14 -14 -14 -14 1 1 1 1 1 1 1 1 1 15 15
stdout
The 5 numbers with max product are: -14 -14 -14 -14 15