int main()
{
int _bottle = 0;//当空瓶为奇数个时,表示剩下的瓶子
int money = 20;
int count = 0;//总共的汽水数
int bottle=0;//空瓶数
if (money > 0)
{
count = money;
bottle = money;
}
while (bottle != 1)
{
if (bottle % 2 == 0)
{
count += bottle / 2;
bottle = bottle / 2;
}
else
{
count += bottle / 2;
_bottle = bottle % 2;
bottle = bottle / 2 + _bottle;
}
}
printf("%d\n", count);
return 0;
}
喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水。编程实现。
最新推荐文章于 2021-05-23 21:51:08 发布