package com.patience.interview.huawei;
import java.util.Scanner;
/**
* 模拟汽水兑换过程
* @author Green.Gee
* @date 2022/8/22 14:15
* @email green.gee.lu@gmail.com
*/
public class SweetWater {
/**
* 每三个空瓶可换一瓶汽水
* 如果不满足三个可以借,但是必须还
* 根据输入N 计算最多可以喝多少瓶汽水
*/
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
String line = in.nextLine();
if("0".equals(line)) continue;
int r = 0;
int n = Integer.valueOf(line);
int mod = n % 3;
int divide = n / 3;
r += divide;
int a = divide + mod;
while(a >= 3){
mod = a % 3;
divide = a / 3;
r += divide;
a = divide + mod;
}
int b = divide + mod + 1;
while(b >= 3) {
mod = b % 3;
divide = b / 3;
r += divide;
b = divide + mod + 1;
}
System.out.println(r);
}
}
}
模拟汽水兑换过程 java
最新推荐文章于 2024-08-24 22:01:16 发布