C++版本计算n元钱可以喝多少瓶啤酒原理讲解及代码实现
#include <iostream>
using namespace std
;
int GetCount(int nBottle
,int nBottleCap
,int nBottleEmpty
)
{
if (nBottleEmpty
< 2 && nBottleCap
< 4)
return nBottle
;
int nChange_Bottle
= nBottleEmpty
/ 2;
int nChange_Bottle_Over
= nBottleEmpty
% 2;
int nChange_BottleCap
= nBottleCap
/ 4;
int nChange_BottleCap_Over
= nBottleCap
% 4;
return GetCount(nBottle
+ nChange_Bottle
+ nChange_BottleCap
, nChange_Bottle
+ nChange_BottleCap
+ nChange_BottleCap_Over
, nChange_Bottle
+ nChange_BottleCap
+ nChange_Bottle_Over
);
}
int main(int argc
, char* argv
[])
{
int nMoeny
= 12;
int nBootle
= nMoeny
/ 2;
int nCount
= GetCount(nBootle
, nBootle
, nBootle
);
printf("\n%d元,能够喝%d瓶啤酒\n", nMoeny
, nCount
);
return 1;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-20545.html