File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.StringTokenizer ;
4+
5+ public class BJ_1107_ 리모컨 {
6+
7+ private static final BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
8+ private static final BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
9+ private static StringTokenizer st;
10+
11+ private static int N , M , ans;
12+ private static String [] malfunctioningButtons;
13+
14+ public static void main (String [] args ) throws IOException {
15+ init();
16+ sol();
17+ }
18+
19+ private static void init () throws IOException {
20+ N = Integer . parseInt(br. readLine());
21+ M = Integer . parseInt(br. readLine());
22+ ans = Math . abs(N - 100 );
23+
24+ malfunctioningButtons = new String [M ];
25+
26+ if (M > 0 ) {
27+ st = new StringTokenizer (br. readLine());
28+ for (int i = 0 ; i < M ; i++ ) {
29+ malfunctioningButtons[i] = st. nextToken();
30+ }
31+ }
32+ }
33+
34+ private static void sol () throws IOException {
35+ for (int i = 0 ; i <= 1000000 ; i++ ) {
36+ String check = String . valueOf(i);
37+
38+ boolean flag = true ;
39+ for (String malfunctioningButton : malfunctioningButtons) {
40+ if (check. contains(malfunctioningButton)) {
41+ flag = false ;
42+ break ;
43+ }
44+ }
45+ if (flag) {
46+ ans = Math . min(ans, check. length() + Math . abs(N - i));
47+ }
48+ }
49+
50+ bw. write(ans + " " );
51+ bw. flush();
52+ bw. close();
53+ br. close();
54+ }
55+
56+ }
57+ ```
You can’t perform that action at this time.
0 commit comments