๐Ÿ‘ฉโ€๐Ÿ’ป SWEA_3499_ํผํŽ™ํŠธ์…”ํ”Œ

๐Ÿ’ฌ ์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ์˜ ์ˆœ์„œ์— ๋งž๊ฒŒ Queue ์— ๋„ฃ๊ณ  ์ฐจ๋ก€๋Œ€๋กœ ์ถœ๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.


๐Ÿ’ก ํ’€์ด ๋ฐฉ๋ฒ•

  • ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด์„ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ๋‘ ๊ฐœ ๋งŒ๋“ค์–ด ์ˆœ์„œ์— ๋งž๊ฒŒ ๋‹ด์•„์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
  • ์ง์ˆ˜์ผ ๊ฒฝ์šฐ ๋˜‘๊ฐ™์ด ๋“ค์–ด๊ฐ€์ง€๋งŒ ํ™€์ˆ˜์ผ ๊ฒฝ์šฐ๊ฐ€ ๋ฌธ์ œ์˜€์Šต๋‹ˆ๋‹ค.
    - ํ™€์ˆ˜์ผ ๊ฒฝ์šฐ์—๋Š” ๋จผ์ € ์ถœ๋ ฅ๋  ์ž๋ฃŒ๊ตฌ์กฐ์— ํ•œ ๊ฐœ๋ฅผ ๋” ๋„ฃ์–ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
  • ์ถœ๋ ฅํ•  ๋•Œ์—๋„ ํ™€์ˆ˜์ด๋ฉด ํ•œ๋ฒˆ ๋” ์ถœ๋ ฅํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”ฅ ์ฝ”๋“œ

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class SWEA_3499_ํผํŽ™ํŠธ์…”ํ”Œ {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 1; t <= T; t++) {
			Queue<String> card = new LinkedList<>();
			Queue<String> card_2 = new LinkedList<>();
			int num = sc.nextInt();
			int cnt = 0;

			for (int i = 0; i < num; i++) {
				if (num % 2 == 0) {
					if (num / 2 > i) {
						card.add(sc.next());
					} else {
						card_2.add(sc.next());
					}
				}
				if (num % 2 == 1) {
					if (num / 2 + 1 > i) {
						card.add(sc.next());
					} else {
						card_2.add(sc.next());
					}
				}
			}
			System.out.print("#" + t);
			while (!card_2.isEmpty() && !card.isEmpty()) {
				System.out.print(" ");
				System.out.print(card.poll());
				System.out.print(" ");
				System.out.print(card_2.poll());
			}
			if (num % 2 == 1) {
				System.out.print(" " + card.poll());
			}
			System.out.println();
		}
	}

}

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ