Home [BOJ 6603] 로또
Post
Cancel

[BOJ 6603] 로또

로또 (6603번)

https://www.acmicpc.net/problem/6603

풀이방법

  • 주어지는 로또 번호들은 오름차순으로 주어지며 사전 순으로 출력해야 하므로 주어진 번호 중 6개를 이용해 조합하면 된다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    private static int[] result = new int[6];
    private static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = null;
        int N = 0;

        while(true) {
            st = new StringTokenizer(br.readLine());
            N = Integer.parseInt(st.nextToken());

            if (N == 0) {
                break;
            }

            int[] arr = new int[N];
            for(int i=0; i<arr.length; i++) {
                arr[i] = Integer.parseInt(st.nextToken());
            }

            solve(arr, 0, 0);
            sb.append('\n');
        }


        System.out.println(sb);
    }

    private static void solve(int[] arr, int curIndex, int c) {
        if (c == 6) {
            for(int i : result) {
                sb.append(i).append(' ');
            }
            sb.append('\n');
            return;
        }
        else {
            for(int i=curIndex; i<arr.length; i++) {
                result[c] = arr[i];
                solve(arr, i+1, c+1);
            }
        }
    }
}

This post is licensed under CC BY 4.0 by the author.

[BOJ 10971] 외판원 순회 2

[BOJ 1037] 약수

Comments powered by Disqus.