File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
weekly/week03/BOJ_6603_로또 Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ package stduy .week03 ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
6+ import java .util .ArrayList ;
7+ import java .util .List ;
8+
9+ // 로또
10+ public class BOJ_6603 {
11+
12+ static StringBuilder sb = new StringBuilder ();
13+ static List <Integer > list ;
14+ static int [] arr ;
15+
16+ public static void main (String [] args ) throws IOException {
17+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
18+
19+ while (true ) {
20+ String [] s = br .readLine ().split (" " );
21+ int K = Integer .parseInt (s [0 ]);
22+ if (K == 0 ) {
23+ break ;
24+ }
25+ arr = new int [K ];
26+ list = new ArrayList <>();
27+
28+ for (int i = 0 ; i < K ; i ++) {
29+ arr [i ] = Integer .parseInt (s [i + 1 ]);
30+ }
31+
32+ backtrack (0 , 0 , K );
33+ sb .append ("\n " );
34+ }
35+
36+ System .out .println (sb );
37+ }
38+
39+ private static void backtrack (int depth , int start , int K ) {
40+ if (depth == 6 ) {
41+ for (int i = 0 ; i < 6 ; i ++) {
42+ sb .append (list .get (i )).append (" " );
43+ }
44+ sb .append ("\n " );
45+ return ;
46+ }
47+
48+ for (int i = start ; i < K ; i ++) {
49+ list .add (arr [i ]);
50+ backtrack (depth + 1 , i + 1 , K );
51+ list .remove (list .size () - 1 );
52+ }
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments