酒瓶和瓶盖换购新酒

首先约定一下不许赊账;其次,改变一下,输入钱的数量再计算。

于是有下面的代码:

 1 #include <stdio.h>
 2 int main(int argc, char *argv[])
 3 {
 4      int money;     //钱的数量 
 5      int bottle;    //空瓶子的数量 
 6      int bottleCap; //瓶盖的数量 
 7      int newBuy;    //新买的数量
 8      int ans=0;     //最后能喝到的数量 
 9      
10      scanf("%d",&money);
11      
12      ans=money/2;   //直接购买得到的数量 
13      bottle=bottleCap=ans;//购买后立即喝完后,空瓶、瓶盖的数量 
14      
15      while(bottle>=2||bottleCap>=4)//只要有条件换购就继续换购 
16      {
17          newBuy=bottle/2+bottleCap/4;//通过换购得到的数量 
18          ans=ans+newBuy; //累计饮用数量 
19          bottle=(bottle&1?1:0)+newBuy;//换购后空瓶的数量发生变化 
20          bottleCap=bottleCap-(bottleCap/4*4)+newBuy;//换购后瓶盖的数量发生变化 
21      }
22      printf("%d\n",ans);
23      return 0;
24 }

 

呵呵就是玩一玩……

 

相关文章:

  • 2021-12-07
  • 2020-05-29
  • 2021-07-13
  • 2021-08-17
  • 2021-07-17
  • 2021-12-29
  • 2022-01-24
  • 2021-08-03
猜你喜欢
  • 2021-09-09
  • 2021-11-30
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案