Skip to content

Commit 197b231

Browse files
authored
[20250918] BOJ / G4 / 리모컨 / 이강현
1 parent 46d744f commit 197b231

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int N, M;
10+
static boolean[] broken = new boolean[10];
11+
12+
public static void main(String[] args) throws IOException {
13+
N = Integer.parseInt(br.readLine());
14+
M = Integer.parseInt(br.readLine());
15+
if(M!=0){
16+
st = new StringTokenizer(br.readLine());
17+
for (int i = 0; i < M; i++) {
18+
broken[Integer.parseInt(st.nextToken())] = true;
19+
}
20+
}
21+
22+
int result = Math.abs(N - 100);
23+
24+
for (int channel = 0; channel <= 1000000; channel++) {
25+
int cnt = getCount(channel);
26+
if (cnt > 0) {
27+
int total = cnt + Math.abs(N - channel);
28+
result = Math.min(result, total);
29+
}
30+
}
31+
32+
bw.write(result+"");
33+
bw.close();
34+
}
35+
36+
static int getCount(int channel) {
37+
if (channel == 0) {
38+
return broken[0] ? -1 : 1;
39+
}
40+
41+
int count = 0;
42+
int temp = channel;
43+
44+
while (temp > 0) {
45+
int digit = temp % 10;
46+
if (broken[digit]) {
47+
return -1;
48+
}
49+
count++;
50+
temp /= 10;
51+
}
52+
53+
return count;
54+
}
55+
}
56+
```

0 commit comments

Comments
 (0)