File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ private static boolean [] Broken = new boolean [10 ];
7+ private static int Target ;
8+ private static int M ;
9+ private static List<Integer > availableButtons = new ArrayList<> ();
10+
11+ public static void main (String [] args ) throws IOException {
12+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
13+ Target = Integer . parseInt(br. readLine());
14+ M = Integer . parseInt(br. readLine());
15+
16+ if (M > 0 ){
17+ StringTokenizer st = new StringTokenizer (br. readLine());
18+ for (int i = 0 ; i < M ; i++ ) {
19+ int b = Integer . parseInt(st. nextToken());
20+ Broken [b] = true ;
21+ }
22+ }
23+
24+ for (int i = 0 ; i <= 9 ; i++ ) {
25+ if (! Broken [i]) availableButtons. add(i);
26+ }
27+ int minPress = Math . abs(Target - 100 );
28+ for (int num = 0 ; num <= 999999 ; num++ ){
29+ if (canMake(num)) {
30+ int pressCount = String . valueOf(num). length() + Math . abs(num - Target );
31+ // System.out.println(pressCount);
32+ minPress = Math . min(minPress, pressCount);
33+ }
34+ }
35+ System . out. println(minPress);
36+ br. close();
37+ }
38+
39+ private static boolean canMake (int num ) {
40+ if (num == 0 )
41+ return ! Broken [0 ];
42+ while (num > 0 ){
43+ if (Broken [num% 10 ])
44+ return false ;
45+ num /= 10 ;
46+ }
47+ return true ;
48+ }
49+ }
50+
51+ ```
You can’t perform that action at this time.
0 commit comments