题解 | #汽水瓶#

汽水瓶

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

全部评论

相关推荐

StephenZ_:我9月份找的第一段实习也是遇到这种骗子公司了,问他后端有多少人和我说7个正职,进去一看只有一个后端剩下的都是产品前端算法(没错甚至还有算法)。还是某制造业中大厂,我离职的时候还阴阳怪气我
点赞 评论 收藏
分享
11-03 14:57
西北大学 营销
Belltrix:其实就是每根转动一定的角度
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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