package com.stxy;
import java.util.Scanner;
/**
* 啤酒2元一瓶,4个瓶盖可以换一瓶啤酒,2个空瓶可以换一瓶啤酒,输入多少钱可以喝多少瓶?
*
*
* @author Administrator
*
*/
public class Test1 {
// 定义一个变量,最终可以喝多少瓶
private static int totalNum;
// 保存当前剩余瓶子盖子数量
private static int leftPingZi, leftGaiZi;
// 拿到钱能买多少瓶
public static void calcNum(int money) {
// 计算买多少瓶、5
int currentNum = money / 2;
// 购买多少瓶加到totalNum
totalNum += currentNum;
// 加上上一轮的瓶子盖子数量为当前数量
int currentLeftPingZi = leftPingZi + currentNum;
int currentLeftGaiZi = leftGaiZi + currentNum;
// 继续换钱去买酒,剩余的钱
int leftMoney = 0;
// 计算瓶子可以换多少钱
if (currentLeftPingZi > 1) {
// 多少钱
int pzMoney = (currentLeftPingZi / 2) * 2;
leftMoney += pzMoney;
// 计算剩余的瓶子
if (currentLeftPingZi % 2 != 0) {
leftPingZi = 1;
} else {
leftPingZi = 0;
}
} else {
leftPingZi = currentLeftPingZi;
}
// 计算盖子可以换多少
if (currentLeftGaiZi > 3) {
// 能换多少钱
int gzMoney = (currentLeftGaiZi / 4) * 2;
leftMoney += gzMoney;
// 计算出当前剩余盖子
leftGaiZi = currentLeftGaiZi - (gzMoney / 2) * 4;
} else {
leftGaiZi = currentLeftGaiZi;
}
if (leftMoney >= 2) {
calcNum(leftMoney);
}
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int money=s.nextInt();
calcNum(money);
System.out.println("瓶数" + totalNum);
System.out.println("剩余瓶子数" + leftPingZi);
System.out.println("剩余瓶子数" + leftGaiZi);
}
}
import java.util.Scanner;
/**
* 啤酒2元一瓶,4个瓶盖可以换一瓶啤酒,2个空瓶可以换一瓶啤酒,输入多少钱可以喝多少瓶?
*
*
* @author Administrator
*
*/
public class Test1 {
// 定义一个变量,最终可以喝多少瓶
private static int totalNum;
// 保存当前剩余瓶子盖子数量
private static int leftPingZi, leftGaiZi;
// 拿到钱能买多少瓶
public static void calcNum(int money) {
// 计算买多少瓶、5
int currentNum = money / 2;
// 购买多少瓶加到totalNum
totalNum += currentNum;
// 加上上一轮的瓶子盖子数量为当前数量
int currentLeftPingZi = leftPingZi + currentNum;
int currentLeftGaiZi = leftGaiZi + currentNum;
// 继续换钱去买酒,剩余的钱
int leftMoney = 0;
// 计算瓶子可以换多少钱
if (currentLeftPingZi > 1) {
// 多少钱
int pzMoney = (currentLeftPingZi / 2) * 2;
leftMoney += pzMoney;
// 计算剩余的瓶子
if (currentLeftPingZi % 2 != 0) {
leftPingZi = 1;
} else {
leftPingZi = 0;
}
} else {
leftPingZi = currentLeftPingZi;
}
// 计算盖子可以换多少
if (currentLeftGaiZi > 3) {
// 能换多少钱
int gzMoney = (currentLeftGaiZi / 4) * 2;
leftMoney += gzMoney;
// 计算出当前剩余盖子
leftGaiZi = currentLeftGaiZi - (gzMoney / 2) * 4;
} else {
leftGaiZi = currentLeftGaiZi;
}
if (leftMoney >= 2) {
calcNum(leftMoney);
}
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int money=s.nextInt();
calcNum(money);
System.out.println("瓶数" + totalNum);
System.out.println("剩余瓶子数" + leftPingZi);
System.out.println("剩余瓶子数" + leftGaiZi);
}
}