喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水。编程实现。

来源:互联网 发布:cmmi软件成熟度模型 编辑:程序博客网 时间:2024/05/17 08:41
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; }

阅读全文
0 0