SZCODE 2020. 8. 9. 19:53

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

 

6603번: 로또

문제 독일 로또는 {1, 2, ..., 49}에서 수 6개를 고른다. 로또 번호를 선택하는데 사용되는 가장 유명한 전략은 49가지 수 중 k(k>6)개의 수를 골라 집합 S를 만든 다음 그 수만 가지고 번호를 선택하는

www.acmicpc.net

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	static int k;
	static int[] S,ans;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			String[] str = br.readLine().split(" ");
			k = Integer.parseInt(str[0]);
			S = new int[k];
			ans = new int[k];
			
			if(k==0) break;
			
			for (int i = 0; i < k; i++) {
				S[i] = Integer.parseInt(str[i+1]);
			}
			//end of input
			
			dfs(0,0);
			System.out.println();
		}//end of while

	}
	public static void dfs(int start, int depth) {
		if(depth == 6) {
			for (int i = 0; i < 6; i++) {
				System.out.print(ans[i]+" ");
			}
			System.out.println();
			return;
		}
		
		for (int i = start; i < k; i++) {
			ans[depth] = S[i];
			dfs(i+1,depth+1);
		}
	
	}
	
}