Coding - Algo/Java
[백준] 6603번:로또 (Java 자바)
jainn
2021. 8. 13. 21:26
728x90
문제
https://www.acmicpc.net/problem/6603
6603번: 로또
입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로
www.acmicpc.net
풀이 및 소스코드
import java.io.*;
import java.util.*;
class Main {
static int n;
static int[] num;
static boolean[] v;
static int[] lotto_list;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
while(true) {
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
if(n==0) break;
num = new int[n];
v = new boolean[n];
lotto_list = new int[6];
for(int i=0;i<n;i++) {
num[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(num);
select_num(0, 0);
System.out.println();
}
}
public static void select_num(int start, int select_cnt) {
if(select_cnt == 6) {
for(int j=0;j<6;j++) {
System.out.print(lotto_list[j]+" ");
}
System.out.println();
return;
}
if(start == n) return;
for(int i=start; i<n;i++) {
lotto_list[select_cnt] = num[i];
select_num(i+1, select_cnt+1);
}
}
}
반응형