Deep_Dev

https://swexpertacademy.com/main/code/problem/problemSolver.do?contestProbId=AWGsRbk6AQIDFAVW 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 


๊นจ๋—ํ•˜๊ฒŒ ํ‘ผ๊ฑฐ๊ฐ™์ง„ ์•Š์€๋ฐ

๋Œ€์ถฉ ํ‘ผ ๋กœ์ง์€

 

๋ฌธ์ž์—ด์„ ์ž…๋ ฅ๋ฐ›๊ณ ๋‚˜์„œ ๋ฐ˜์ ˆ์„ ๊ธฐ์ค€์œผ๋กœ Q1, Q2 ์— ๋‚˜๋ˆ„๊ณ 

์ •๋‹ต์œผ๋กœ ์ถœ๋ ฅํ•  arraylist์— Q1, Q2์— ์žˆ๋Š” ๊ฐ’๋“ค์„ ์ˆœ์„œ๋Œ€๋กœ ๋„ฃ์œผ๋ฉด์„œ ํ๊ฐ€ ๋น„์–ด์ง€๋ฉด stop..

 

 

 

import java.util.Scanner;
import java.util.*;

class Solution{
    public static void main(String args[]) throws Exception{
   
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        for (int t = 1; t <= T; t++) {
            int n=kb.nextInt();
            String[] arr=new String[n];
            for(int i=0; i<n; i++) arr[i]=kb.next();
 
            Queue<String> Q1=new LinkedList<>();
            Queue<String> Q2=new LinkedList<>();
            if(n%2==0){
                for(int i=0; i<n/2; i++) Q1.offer(arr[i]);
                for(int i=n/2; i<n; i++) Q2.offer(arr[i]);
            }
            if(n%2==1){
                for(int i=0; i<(n/2)+1; i++) Q1.offer(arr[i]);
                for(int i=n/2+1; i<n; i++) Q2.offer(arr[i]);
            }
            int size=Math.max(Q1.size(), Q2.size());
             
            ArrayList<String> answer=new ArrayList<>();
            for(int i=0; i<size; i++){
                 if(!Q1.isEmpty()){
                     answer.add(Q1.poll());
                 }
                 if(!Q2.isEmpty()){
                     answer.add(Q2.poll());
                 }
            }
            System.out.print("#"+t);
            for(int i=0; i<n; i++){
                System.out.print(" "+answer.get(i));
            }
            System.out.println();
        }
    }
}