有一种将字母编码成数字的方式:'a'->1, 'b->2', ... , 'z->26'。
现在给一串数字,给出有多少种可能的译码结果。
import java.util.Scanner;
public class Main {
public static int process(char[] ch, int i) {
if (i == ch.length) {
return 1;
}
if (ch[i] == '0') {
return 0;
}
if (ch[i] == '1') {
int res = process(ch, i + 1);
if (i + 1 < ch.length) {
res += process(ch, i + 2);
}
return res;
}
if (ch[i] == '2') {
int res = process(ch, i + 1);
if (i + 1 < ch.length && ch[i] >= '0' && ch[i + 1] <= '6') {
res += process(ch, i + 2);
}
return res;
}
return process(ch, i + 1);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
if (str.length() < 1) {
System.out.println(0);
} else {
System.out.println(process(str.toCharArray(), 0));
}
}
}