题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
import java.util.Scanner;
import java.util.ArrayList;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<Integer> integers = new ArrayList<>();
while (in.hasNextLine()) {
int n = in.nextInt();
if (n > 0) {
if (n < 3) {
integers.add(0);
} else {
integers.add(n / 2);
}
} else {
break;
}
}
for (Integer a : integers) {
System.out.println(a);
}
}
}
说来好笑
我先手动推到了 1 到 11 个空瓶子时,能喝多少瓶汽水,如下:
1 -> 0
2 -> 0
3 -> 1
4 -> 2
5 -> 2
6 -> 3
7 -> 3
8 -> 4
9 -> 4
10 -> 5
11 -> 5
然后我就注意到 结果好像就是 空瓶子数除2取整就行了
抱着试一试的心态,居然过了
hhhhhh

