Skip to content

Commit 2623d06

Browse files
authored
[20250806] BOJ / G5 / 감소하는 수 / 이종환
1 parent 0692077 commit 2623d06

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

0224LJH/6 BOJ 감소하는 수.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.*;
6+
7+
8+
public class Main {
9+
10+
static int target,idx;
11+
static long[] decreasingNum;
12+
13+
14+
public static void main(String[] args) throws IOException {
15+
init();
16+
process();
17+
print();
18+
}
19+
20+
private static void init() throws IOException {
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
target = Integer.parseInt(br.readLine());
23+
decreasingNum = new long[1000001];
24+
Arrays.fill(decreasingNum, -1);
25+
idx = 0;
26+
}
27+
28+
private static void process() throws IOException {
29+
for (int i = 1; i <= 10; i++){
30+
findNum(i-1,0,10);
31+
}
32+
33+
}
34+
35+
private static void findNum(int curPos, long curNum,int limit) {
36+
if (curPos == -1){
37+
decreasingNum[idx++] = curNum;
38+
}
39+
40+
for (int i = 0; i < limit; i++){
41+
long tempNum = (long) (curNum + Math.pow(10,curPos) * i);
42+
findNum(curPos-1,tempNum,i);
43+
44+
}
45+
}
46+
47+
48+
private static void print() {
49+
System.out.println(decreasingNum[target]);
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)