题解 | #汽水瓶#

汽水瓶

http://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f

咱就用这个笨方法吧。


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String input = scanner.nextLine();
            if (input == null) {
                break;
            }
            int num = Integer.parseInt(input);
            int res = drinkNum(num);
            System.out.println(res == 0 ? "" : res);
        }
        scanner.close();
    }

    public static int drinkNum(int bottle) {
        int res = bottle / 3;


        int resTemp = res;
        int last = bottle % 3 + resTemp;


        while (last >= 2) {
            if (last == 2) {
                res += 1;
                break;
            }
            resTemp = last / 3;
            res += resTemp;
            last = last % 3 + resTemp;
        }
        return res;
    }
}

全部评论

相关推荐

09-19 13:59
门头沟学院 Java
用微笑面对困难:Trae一下,如果真成了,他用了直接发字节起诉代码版权,,这个代码不商用是没问题的如果没成也是情理之中的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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