题解 | #操作序列#
操作序列
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()); } }