백준 로또 - 6603 [JAVA] - 23년 1월 5일

Denia·2023년 1월 5일
0

코딩테스트 준비

목록 보기
130/201
post-custom-banner
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

public class Main {
    static public void main(String[] args) throws IOException {
        BjSolution sol = new BjSolution();

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] line = br.readLine().split(" ");
            if (line[0].equals("0")) {
                break;
            }

            sol.solution(line);
            System.out.println();
        }
    }
}

class BjSolution {
    final int LOTTO_NUM = 6;
    Deque<String> queue;
    String[] gQuiz;
    int gNumCount;

    public void solution(String[] quiz) {
        gQuiz = quiz;
        queue = new ArrayDeque<>();
        gNumCount = Integer.parseInt(quiz[0]);

        dfs(1, queue);
    }

    private void dfs(int depth, Deque<String> queue) {
        if (queue.size() == LOTTO_NUM) {
            StringBuilder sb = new StringBuilder();
            List<String> tempList = new ArrayList<>(queue);

            for (String integer : tempList) {
                sb.append(integer).append(" ");
            }

            System.out.println(sb);
            return;
        }

        for (int i = depth; i < gNumCount + 1; i++) {
            queue.addLast(gQuiz[i]);
            dfs(i + 1, queue);
            queue.removeLast();
        }
    }
}

profile
HW -> FW -> Web
post-custom-banner

0개의 댓글