题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int num = in.nextInt(); if (num == 0) { break; } else { System.out.println(getDrink(num)); } } } public static int getDrink(int bottle) { if (bottle <= 1) { return 0; } // 防止无限循环导致的内存溢出 else if (bottle == 2) { return 1; } else { return bottle / 3 + getDrink(bottle / 3 + bottle % 3); } } }#23届找工作求助阵地#