题解 | #操作序列#

操作序列

https://www.nowcoder.com/practice/75411105c14a4091983f1cb232bd243e

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        ArrayDeque<Integer> dq = new ArrayDeque<>();
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        if(n % 2 == 0) {
            for(int i = 0; i < n; i++, i++) {
                dq.offerLast(arr[i]);
                dq.offerFirst(arr[i + 1]);
            }
        } else {
            dq.offer(arr[0]);
            for(int i = 1; i < n; i++, i++) {
                dq.offerLast(arr[i]);
                dq.offerFirst(arr[i + 1]);
            }
        }

        for(int i = 0; i < n - 1; i++) {
            System.out.print(dq.pollFirst() + " ");
        } 
        System.out.print(dq.pollFirst());
    }
}

全部评论
哎呀妈呀,终于刷到校友了
点赞 回复 分享
发布于 2022-12-15 14:51 北京

相关推荐

不愿透露姓名的神秘牛友
今天 12:11
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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