华为OD机试真题 - 转盘寿司

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] price = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] newPrice = getLastPrice(price);
        for (int i = 0; i < newPrice.length; i++) {
            System.out.print(newPrice[i] + &quot; &quot;);
        }
    }

    public static int[] getLastPrice(int[] price) {
        int[] newPrice = new int[price.length];
        for (int i = 0; i < price.length; i++) {
            if (i + 1 < price.length &amp;&amp; price[i + 1] < price[i])
                newPrice[i] = price[i] + price[i + 1];
            else
                newPrice[i] = price[i];
        }
        if (newPrice[price.length - 1] > price[0])
            newPrice[price.length - 1] += price[0];
        return newPrice;
    }
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 18:02
好不容易拿到了字节Offer,鼠鼠做后端的,但家里人觉得可能被裁员不稳定,让鼠鼠去投国企,现在好纠结到底该咋选
文档传偷助手:该投就投吧,不过建议别放弃offer 拿到手里的才是最好的
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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