https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWGsRbk6AQIDFAVW
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
public static void main (String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
Queue<String> leftQueue = new LinkedList<>();
Queue<String> rightQueue = new LinkedList<>();
for (int n = 0; n < (N+1)/2; n++)
leftQueue.offer(st.nextToken());
for (int n = (N+1)/2; n < N; n++)
rightQueue.offer(st.nextToken());
System.out.print("#" + t + " ");
while (!leftQueue.isEmpty() || !rightQueue.isEmpty()) {
if (!leftQueue.isEmpty())
System.out.print(leftQueue.poll() + " ");
if (!rightQueue.isEmpty())
System.out.print(rightQueue.poll() + " ");
}
System.out.println();
}
}
}
'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
[Algorithm] 백준 2798 블랙잭 (0) | 2021.08.08 |
---|---|
[Algorithm] 백준 2751 수 정렬하기 2 (0) | 2021.08.08 |
[Algorithm] SWEA 1861 정사각형 방 (0) | 2021.08.06 |
[Algorithm] SWEA 1940 가랏! RC카! (0) | 2021.08.05 |
[Algorithm] SWEA 1225 암호생성기 (0) | 2021.08.05 |