您的位置首页百科问答

每瓶啤酒2元,2个空酒瓶或4个瓶盖可换1瓶啤酒。10元最多可喝多少瓶啤酒?

每瓶啤酒2元,2个空酒瓶或4个瓶盖可换1瓶啤酒。10元最多可喝多少瓶啤酒?

的有关信息介绍如下:

每瓶啤酒2元,2个空酒瓶或4个瓶盖可换1瓶啤酒。10元最多可喝多少瓶啤酒?

public class Test {

/**

* @param args

*/

public static int all = 5;

public static int leftBottle;

public static int leftTop;

public static void main(String[] args) {

all = all + drink(5,5);

System.out.println("总共能喝"+all);

System.out.println("剩下酒瓶个数"+leftBottle);

System.out.println("剩下盖子个数"+leftTop);

}

public static int drink(int bottle, int top) {

if(bottle >=2 || top >=4){

leftBottle = (bottle/2)+(bottle%2)+(top/4);

leftTop = (top/4) + (top%4) + (bottle/2);

return (bottle/2) + (top/4) + drink(leftBottle,leftTop);

}

return 0;

}

}

运行结果:

总共能喝15

剩下酒瓶个数1

剩下盖子个数3

如果可以赊账,则是1楼的答案:20瓶