题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
不抖机灵,正常使用递归的代码
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = null;
while (!"0".equals((str = br.readLine()))) {
int bottle = Integer.parseInt(str);
System.out.println(getResult(bottle));
}
}
public static int getResult(int bottle){
int result = 0;
result += bottle / 3;
int left = bottle % 3;
if(result + left > 2){
result += getResult(result + left);
} else if(result + left == 2){
result++;
}
return result;
}
}
