Skip to content

Commit ee6c3e5

Browse files
authored
[20251209] BOJ / G5 / 암호코드 / 강신지
1 parent 6121a7b commit ee6c3e5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```java
2+
import java.io.*;
3+
4+
public class Main {
5+
static final int MOD = 1000000;
6+
7+
public static void main(String[] args) throws Exception {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
String s = br.readLine();
10+
11+
int n = s.length();
12+
if (n == 0 || s.charAt(0) == '0') {
13+
System.out.println(0);
14+
return;
15+
}
16+
17+
int[] dp = new int[n + 1];
18+
dp[0] = 1;
19+
dp[1] = 1;
20+
21+
for (int i = 2; i <= n; i++) {
22+
char c1 = s.charAt(i - 1);
23+
char c0 = s.charAt(i - 2);
24+
25+
if (c1 != '0') {
26+
dp[i] += dp[i - 1];
27+
dp[i] %= MOD;
28+
}
29+
30+
int two = (c0 - '0') * 10 + (c1 - '0');
31+
if (two >= 10 && two <= 26) {
32+
dp[i] += dp[i - 2];
33+
dp[i] %= MOD;
34+
}
35+
}
36+
37+
System.out.println(dp[n] % MOD);
38+
}
39+
}
40+
41+
```

0 commit comments

Comments
 (0)