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