11import java .io .*;
22import java .util .*;
33public class Main {
4-
5- static int total ;
6- static int [] people , selected ;
4+ static boolean flag ;
5+ static int [] cm , selected ;
76 static StringBuilder sb = new StringBuilder ();
87 static BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
9-
10- /*
11- note
12- 난쟁이 9명 중 7먕을 골라 100만들기
13- 1. 모든 난쟁이의 조함 => 9C7
14- 2. 모든 난쟁이 합 - 2명 골라서 빼기
15-
16- */
17- public static void main (String [] args ) throws Exception {
18- people = new int [9 ];
19- selected = new int [2 ];
20-
21- for (int i = 0 ; i < 9 ; i ++) {
22- people [i ] = Integer .parseInt (br .readLine ());
23- total += people [i ];
24- }
25- Arrays .sort (people );
8+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
9+ public static void main (String [] args ) throws Exception {
10+ pre_setting ();
2611 combi (0 , 0 , 0 );
27- }
12+ bw .append (sb );
13+ bw .close ();
2814
29- public static void combi (int start , int cnt , int sum ){
30- if (cnt == 2 ){
31- if (total - sum == 100 ){
32- for (int i = 0 ; i < 9 ; i ++) {
33-
34- if (selected [0 ] == people [i ]) continue ;
35- if (selected [1 ] == people [i ]) continue ;
36- sb .append (people [i ]).append ("\n " );
15+ }
3716
38- }
39- System .out .println (sb );
40- System .exit (0 );
17+ static void combi (int cnt , int sum , int start ){
18+ if (cnt == 7 ){
19+ if (sum == 100 && !flag ){
20+ for (int i = 0 ; i < 7 ; i ++) sb .append (selected [i ]).append ("\n " );
21+ flag = true ;
4122 }
4223 return ;
4324 }
44- for (int i = start ; i < 9 ; i ++) {
45- selected [cnt ] = people [i ];
46- combi (i + 1 , cnt + 1 , sum + people [i ]);
25+ for (int i = start ; i < 9 ; i ++){
26+ selected [cnt ] = cm [i ];
27+ combi (cnt + 1 , sum + cm [i ], i + 1 );
4728 }
4829 }
4930
31+ static void pre_setting () throws Exception {
32+ cm = new int [9 ];
33+ selected = new int [7 ];
34+
35+ for (int i = 0 ; i < 9 ; i ++) cm [i ] = Integer .parseInt (br .readLine ());
36+ Arrays .sort (cm );
37+ }
38+
5039}
0 commit comments