조합문제

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
 
public class Main6603_로또 {
    private static int K;
    private static int[] lotto;
    private static ArrayList<Integer> list;
 
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        
        while(true) {
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        K = Integer.parseInt(st.nextToken());
        if(K==0) {
            break;
        
        }
        list = new ArrayList<>();
        lotto = new int[K];
        for (int i = 0; i < K; i++) {
            lotto[i] = Integer.parseInt(st.nextToken());
        }        
        comb(00);
        System.out.println();
        }
        
 
    }// end of main
 
    public static void comb(int idx, int k) {
        if (idx == 6) {
            for (int i = 0; i < list.size(); i++) {
                System.out.print(list.get(i) + " ");
            }
            System.out.println();
            return;
        }
        
        for (int i = k; i < lotto.length; i++) {
            list.add(lotto[i]);
            comb(idx + 1, i + 1);
            list.remove(list.size() - 1);
        }
 
    }
 
}// end of class
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

+ Recent posts