File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.BufferedReader ;
3+ import java.io.IOException ;
4+ import java.io.InputStreamReader ;
5+
6+ public class Main {
7+ public static void main (String [] args ) throws IOException {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
9+ String s = br. readLine();
10+ int n = s. length();
11+ int MOD = 1_000_000 ;
12+ int [] dp = new int [n + 1 ];
13+ if (s. charAt(0 ) == ' 0' ) {
14+ System . out. println(0 );
15+ return ;
16+ }
17+
18+
19+ dp[0 ] = 1 ;
20+ dp[1 ] = 1 ;
21+ for (int i = 2 ; i <= n; i++ ) {
22+ char now = s. charAt(i - 1 );
23+ char previous = s. charAt(i - 2 );
24+ // 한자리수
25+ if (now != ' 0' ) {
26+ dp[i] = (dp[i] + dp[i - 1 ]) % MOD ;
27+ }
28+
29+ // 두자리수
30+ int twoDigit = (previous - ' 0' ) * 10 + (now - ' 0' );
31+ if (twoDigit >= 10 && twoDigit <= 26 ) {
32+ dp[i] = (dp[i] + dp[i - 2 ]) % MOD ;
33+ }
34+ }
35+ System . out. println(dp[n]);
36+ }
37+ }
38+
39+ ```
You can’t perform that action at this time.
0 commit comments