Algo-1 buatan saya sendiri
Algo-2, algo dari buku Ivon Horton (kurang maksimal)
#include <iostream>
using namespace std;
int divbox (double a_lwv[6], int algo = 1);
int main()
{
double theboxes[6];
int i;
char exit_y;
do
{
for (i=0;i<=5;i++)
{
cout << "Enter input(" << i << ") = ";
cin >> theboxes[i];
cout << endl;
}
cout << "Max div box = " << divbox(theboxes) << endl;
cout << "Horton div box = " << divbox(theboxes,2) << endl;
cout << endl << "Exit (y) ? " ;
cin >> exit_y;
} while (exit_y != 'y');
return 0;
}
int divbox (double a_lwv[6], int algo)
{
int i,j;
int maxbox = 0, trialbox;
double lwv[3] = {a_lwv[0], a_lwv[1], a_lwv[2]};
if (algo==1)
{
for (i=0;i<=2;i++)
for (j=0;j<=2;j++)
if (i != j)
if (maxbox < (trialbox = static_cast<int>(lwv[i]/a_lwv[3]) *
static_cast<int>(lwv[j]/a_lwv[4]) *
static_cast<int>(lwv[3-(i+j)]/a_lwv[5])))
maxbox = trialbox;
} else {
int tc1 = 0;
int tc2 = 0;
tc1 = static_cast<int>(lwv[0]/a_lwv[3])*
static_cast<int>(lwv[1]/a_lwv[4]);
tc1 = static_cast<int>(lwv[0]/a_lwv[4])*
static_cast<int>(lwv[1]/a_lwv[3]);
maxbox = static_cast<int>(lwv[2]/a_lwv[5])*
(tc1>tc2?tc1:tc2);
}
return maxbox;
}