题解 | #汽水瓶#

汽水瓶

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

欢迎大家来优化一下,我觉得我写得很暴力


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int EmptyBottle;
        int ColaDrink;
        out:while (sc.hasNext()) {
            EmptyBottle = Integer.parseInt(sc.nextLine());
            ColaDrink=0;
            if (EmptyBottle == 0) {
                break out;
            }
            do {
                if (EmptyBottle >=3) {
                    ColaDrink += EmptyBottle / 3;
                    EmptyBottle=EmptyBottle/3+EmptyBottle%3;
                }
                if (EmptyBottle == 2) {
                    ColaDrink++;
                    EmptyBottle=0;
                    break ;
                }
//下面这句可以没有
                if (EmptyBottle==1){
                    ColaDrink+=0;
                }
            } while (EmptyBottle != 1);
            System.out.println(ColaDrink);
        }
    }
}


全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:29
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
Steven267:这不喷回去?花钱是大爷,记住这个道理
点赞 评论 收藏
分享
缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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