题解 | #汽水瓶#

汽水瓶

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int[] a = new int[10];
        int i = 0;
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int next = in.nextInt();
            if(next == 0){
                break;
            }
            a[i++] = next;
        }
        for(int n : a){
            if(n == 0){
                break;
            }
            int m = 0;//喝的数量
            while(true){
                if(n>=3){
                    m += (n/3);
                    n = n%3 + (n/3);//剩余空瓶
                }
                else if(n == 2){
                    m++;
                    break;
                }else{
                    break;
                }
                
            }
            System.out.println(m);
            
        }
         //System.out.println(m);
    }
}

全部评论

相关推荐

勤奋努力的椰子这就开摆:这些经历跟硬件都没啥关系呀
点赞 评论 收藏
分享
03-27 17:33
门头沟学院 Java
代码飞升:同学院本,你要注意hr当天有没有回复过,早上投,还要打招呼要推销自己,不要一个劲投
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务