Skip to content

Commit 6466628

Browse files
authored
Merge pull request #1347 from AlgorithmWithGod/0224LJH
[20251108] BOJ / G4 / 리모컨 / 이종환
2 parents 3ab05f2 + ed756c8 commit 6466628

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

0224LJH/202511/08 BOJ 리모컨.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.Arrays;
6+
import java.util.HashMap;
7+
import java.util.HashSet;
8+
import java.util.LinkedList;
9+
import java.util.Queue;
10+
import java.util.StringTokenizer;
11+
12+
public class Main {
13+
14+
static int ans,target;
15+
static HashSet<Integer> banSet = new HashSet<>();
16+
17+
public static void main(String[] args) throws IOException {
18+
init();
19+
process();
20+
print();
21+
}
22+
23+
private static void init() throws IOException{
24+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));;
25+
target = Integer.parseInt(br.readLine());
26+
27+
int banCnt = Integer.parseInt(br.readLine());
28+
if (banCnt == 0) return;
29+
StringTokenizer st = new StringTokenizer(br.readLine());
30+
for (int i = 0; i < banCnt; i++) {
31+
banSet.add(Integer.parseInt(st.nextToken()));
32+
}
33+
}
34+
35+
36+
private static void process() {
37+
ans = Math.abs(target - 100);
38+
39+
for (int i = 0 ; i < 1000000; i++) {
40+
int num = i;
41+
int diff = Math.abs(target - num);
42+
int len = String.valueOf(num).length();
43+
boolean isPossible = true;
44+
while(true) {
45+
if (banSet.contains(num%10)) {
46+
isPossible = false;
47+
break;
48+
}
49+
50+
num /= 10;
51+
if (num == 0) break;
52+
}
53+
54+
if (isPossible) ans = Math.min(ans, diff+len);
55+
}
56+
}
57+
58+
59+
60+
private static void print() {
61+
System.out.println(ans);
62+
}
63+
}
64+
65+
66+
```

0 commit comments

Comments
 (0)