Skip to content

Commit 5847e79

Browse files
authored
Merge pull request #1151 from AlgorithmWithGod/zinnnn37
[20251017] BOJ / G4 / 리모컨 / 김민진
2 parents 0c4e3ed + 4f3e1af commit 5847e79

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
```

0 commit comments

Comments
 (0)