Title: The famous French mathematician, Virgin, studied an interesting mathematical problem in the time of the year: someone had a bottle of 12 pints of beer and wanted to pour 6 pints out of it, but he didn't have 6 pints of container, only 8 pints and 5 pints of containers, how to divide the beer into two pints.
/* Title: Virgin, a famous French mathematician, studied an interesting mathematical problem in the time of the year
: someone had a bottle of 12 pints of beer to
pour out 6 pints, but he did not have 6 pints of container, only a 8 pint
and 5 pint container, How to divide a beer into two 6 pints. by
as1138 2012-08-13
*/
#include <iostream>
using namespace std;
int main (int argc, char const *argv[])
{
int nTw = n;
int nEi = 0;
int nFi = 0;
while (true)
{
if (nEi = = 0)//8 capacity bottle is empty
{
nTw-= 8;
NEi + = 8;
}
else if (nFi = = 5)//5 capacity bottle is full
{
nTw + = 5;
nFi = 0;
}
else if (NFi < 5)//5 capacity bottle is not full
{
int nT = 5-NFI;
if (NT > NEi)
{
nFi + = nEi;
nEi = 0;
}
else
{
NEi-= NT;
NFi + = NT;
}
}
cout<<ntw<< "" <<nEi<< "" <<nFi<<endl;
if (nTw = = 6&&nei = = 6) break
;
cout<< " ↓" <<endl;
} End
while return 0;
}