๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ฝ”๋”ฉํ…Œ์ŠคํŠธ/TIL

[99ํด๋Ÿฝ] 14์ผ์ฐจ ๋ฌธ์ œ: ์‹๋‹น ๋ฉ”๋‰ด

by moon101 2025. 2. 6.

 

 

 

์˜ค๋Š˜์„ ๋ฐฑ์ค€ ์‹๋‹น๋ฉ”๋‰ด ๋ฌธ์ œ์˜€๋Š”๋ฐ ๋ฌธ์ œ๊ฐ€ ์ดํ•ดํ•˜๊ธฐ ๋„ˆ๋ฌด ์–ด๋ ค์› ๋‹ค. ๊ทธ๋ž˜์„œ ๋‹ต์•ˆ์„ ์ฐธ๊ณ ํ–ˆ๋Š”๋ฐ ์ฝ๊ณ  ๋‚˜๋‹ˆ ์–ด๋ ค์šด ๋ฌธ์ œ๋Š” ์•„๋‹ˆ์˜€๋Š”๋ฐ ๋ฌธ์ž์—ด ์ž…๋ ฅ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผ ํ•ด์„œ ๋” ๋ณต์žกํ•ด์ง„ ๊ฒƒ ๊ฐ™๋‹ค. ์ฝ”๋“œ๋„ ๊ธธ์–ด์ง€๊ณ . ๋ฐ‘์— ์ฝ”๋“œ๋Š” GPT๋ฅผ ๋„์›€์„ ๋ฐ›์•„ ์ž‘์„ฑํ–ˆ๋‹ค.

 

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(br.readLine()); // ์ •๋ณด์˜ ๊ฐœ์ˆ˜

        List<Integer> listA = new ArrayList<>(); // ์›ํ•˜๋Š” ๊ฑธ ๋จน์€ ํ•™์ƒ
        List<Integer> listB = new ArrayList<>(); // ์›ํ•˜์ง€ ์•Š๋Š” ๊ฑธ ๋จน์€ ํ•™์ƒ
        List<Integer> listC = new ArrayList<>(); // ๋ชป ๋จน์€ ํ•™์ƒ

        Deque<int[]> queue = new LinkedList<>(); // ์‹๋‹น ๋Œ€๊ธฐ ์ค„ (FIFO)

        for (int i = 0; i < n; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int type = Integer.parseInt(st.nextToken());

            if (type == 1) { // ํ•™์ƒ ๋„์ฐฉ
                int student = Integer.parseInt(st.nextToken());
                int favoriteMenu = Integer.parseInt(st.nextToken());
                queue.offer(new int[]{student, favoriteMenu});
            } else { // ์Œ์‹ ์ค€๋น„๋จ
                int menuReady = Integer.parseInt(st.nextToken());

                if (!queue.isEmpty()) {
                    int[] student = queue.poll(); // ๋Œ€๊ธฐ์—ด์˜ ์ฒซ ๋ฒˆ์งธ ํ•™์ƒ

                    if (student[1] == menuReady) { // ์›ํ•˜๋Š” ๋ฉ”๋‰ด๋ฅผ ๋จน์Œ
                        listA.add(student[0]);
                    } else { // ์›ํ•˜์ง€ ์•Š๋Š” ๋ฉ”๋‰ด๋ฅผ ๋จน์Œ
                        listB.add(student[0]);
                    }
                }
            }
        }

        // ์ค„์— ๋‚จ์•„ ์žˆ๋Š” ํ•™์ƒ๋“ค์€ ๋จน์ง€ ๋ชปํ•œ ํ•™์ƒ๋“ค
        while (!queue.isEmpty()) {
            listC.add(queue.poll()[0]);
        }

        // ์ •๋ ฌ ํ›„ ์ถœ๋ ฅ
        printList(sb, listA);
        printList(sb, listB);
        printList(sb, listC);

        bw.write(sb.toString());
        bw.flush();
        bw.close();
        br.close();
    }

    // ๋ฆฌ์ŠคํŠธ ์ •๋ ฌ ๋ฐ ์ถœ๋ ฅ ํ•จ์ˆ˜
    private static void printList(StringBuilder sb, List<Integer> list) {
        if (list.isEmpty()) {
            sb.append("None\n");
        } else {
            Collections.sort(list);
            for (int num : list) {
                sb.append(num).append(" ");
            }
            sb.append("\n");
        }
    }
}
 
 

๋Œ“๊ธ€