题解 | #汽水瓶#

汽水瓶

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int v = in.nextInt();
            int r = heqishui(v);
            if (r != 0)
                System.out.println(r);
        }
    }

    public static int heqishui(int num) {
        int count = 0;

        while (num >= 3) {
            // 本轮剩余
            int remain = 0;
            count += num / 3;
            if (num > 3) {
                remain = num % 3;
            }
            num = num / 3 + remain;
            if (num == 2) {
                num += 1;
            }
        }
        return count;
    }
}
全部评论

相关推荐

10-30 22:18
已编辑
毛坦厂中学 C++
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务