题解 | #汽水瓶#

汽水瓶

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;
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务