File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+
3+ import java.io.* ;
4+ import java.util.* ;
5+
6+ public class Main {
7+
8+ static boolean [] broken = new boolean [10 ];
9+
10+ public static void main (String [] args ) throws Exception {
11+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
12+
13+ int n = Integer . parseInt(br. readLine(). trim());
14+ int m = Integer . parseInt(br. readLine(). trim());
15+
16+ if (m > 0 ) {
17+ StringTokenizer st = new StringTokenizer (br. readLine());
18+ for (int i = 0 ; i < m; i++ ) {
19+ broken[Integer . parseInt(st. nextToken())] = true ;
20+ }
21+ }
22+
23+ int answer = Math . abs(n - 100 );
24+
25+ for (int ch = 0 ; ch <= 1000000 ; ch++ ) {
26+ int len = canpress(ch);
27+ if (len == - 1 ) continue ;
28+ int press = len + Math . abs(n - ch);
29+ if (press < answer) answer = press;
30+ }
31+
32+ System . out. println(answer);
33+ }
34+
35+ static int canpress (int ch ) {
36+ if (ch == 0 ) return broken[0 ] ? - 1 : 1 ;
37+ int len = 0 ;
38+ while (ch > 0 ) {
39+ int d = ch % 10 ;
40+ if (broken[d]) return - 1 ;
41+ len++ ;
42+ ch /= 10 ;
43+ }
44+ return len;
45+ }
46+ }
47+
48+ ```
You can’t perform that action at this time.
0 commit comments