题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = br.readLine())!= null) { int n = Integer.parseInt(str); if(n == 0) return; System.out.println(drink(n)); } } private static int drink(int x) { int nullBottle=x; int drinkNum = 0; while(nullBottle -3 >= 0) { nullBottle = nullBottle -3; drinkNum++; nullBottle++; } if(nullBottle == 2) { nullBottle = 0; drinkNum ++; } return drinkNum; } }