题解 | #汽水瓶#

汽水瓶

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

全部评论

相关推荐

2025-12-25 16:26
已编辑
河北科技学院 Java
勇敢的牛油不服输:2800-300那不等于2500一个月吗兄弟们
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务