SWEA 3499パーフェクトセット


Queueで一番前の値を抽出して新しいリストに入れればいいです
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Solution {
	static BufferedReader br;
	static BufferedWriter bw;
	static StringTokenizer st;
	static LinkedList<String> p1, p2, output;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		bw = new BufferedWriter(new OutputStreamWriter(System.out));
		int T = Integer.parseInt(br.readLine());
		
		for (int tc = 1; tc <= T; tc++) {
			int N = Integer.parseInt(br.readLine());
			p1 = new LinkedList<>();
			p2 = new LinkedList<>();
			output = new LinkedList<>();
			st = new StringTokenizer(br.readLine(), " ");
			for (int i = 0; i < (N + 1) / 2; i++) {
				p1.add(st.nextToken());
			}
			for (int i = (N+1) / 2; i < N; i++) {
				p2.add(st.nextToken());
			}
			for(int i = 0; i < N; i++) {
				if(i % 2 == 0) {
					output.add(p1.poll());
				}else {
					output.add(p2.poll());
				}
			}
			
			bw.append("#" + tc + " ");
			for(String t : output) {
				bw.append(t + " ");
			}
			bw.append("\n");

		}
		bw.flush();
		bw.close();

	}
}