import java.util.Scanner; import java.util.ArrayList; import java.util.List; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { /* * 三个空汽水瓶可以换一瓶汽水 总共有n个空汽水瓶 0=<n<=100 当n=0时代表输入结束*/ Scanner scanner = new Scanner(System.in); List<Integer> emptySodaBottle = new ArrayList<>(); while (scanner.hasNextLine()) { String exit = scanner.nextLine(); if (exit.equals("0")) { break; } emptySodaBottle.add(Integer.parseInt(exit)); } for (int i = 0; i < emptySodaBottle.size(); i++) { int emptySodeBottleNumber = emptySodaBottle.get(i); System.out.println(maximumAmountOfSodaToDrink(emptySodeBottleNumber)); } } private static int maximumAmountOfSodaToDrink(int emptySodeBottleNumber) { int num = 0; //可以喝的数量 int discuss = 0;//商的数量 int remainder = 0;//余数的数量 //10 3+1+1 4 2 if (emptySodeBottleNumber >= 3) { discuss = emptySodeBottleNumber / 3; num += discuss; remainder = emptySodeBottleNumber % 3; emptySodeBottleNumber = discuss + remainder; num += maximumAmountOfSodaToDrink(emptySodeBottleNumber); } else if (emptySodeBottleNumber == 2) { num++; } return num; } }