华为OD机试D卷-特惠寿司(100分)JAVA

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] prices = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] sushi = solveSushi(prices);
        for (int i : sushi) {
            System.out.printf("%d ", i);
        }
    }

    private static int[] solveSushi(int[] prices) {
        int len = prices.length;
        int[] pricesDis = new int[len * 2];
        for (int i = 0; i < pricesDis.length; i++) {
            pricesDis[i] = prices[i % len]; //给新数组赋值,模拟转盘
        }
        for (int i = 0; i < len; i++) {
            for (int j = i + 1; j < i + len; j++) {
                if (pricesDis[j] < pricesDis[i]) {
                    prices[i] = pricesDis[j] + pricesDis[i];
                    break;
                }
            }
        }
        return prices;
    }
}

全部评论

相关推荐

在改简历的大卫很认真:天天有面试 = 你已经在 offer 门口了。 海投能面成这样,说明你的简历、基础、学历都是过关的,缺的只是一次刚好匹配的缘分。 关于你说的 SQL 恐惧,我帮你捋一下: - 面试里考来考去,真就那几类: 分组、去重、关联、子查询、窗口函数(row_number、rank、sum 开窗) ​ - 面试官要的不是“写得花里胡哨”,而是思路稳、不出错。 你恐惧的本质不是不会, 是怕临场卡壳、怕写错、怕被追问。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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