import java.util.*;
public class Transfer {
public static void main(String[] args) {
Map<Integer, Integer> mapint = new HashMap<Integer, Integer>();
int count = 0;
int sum = 0; //calculate result
Map<String, Integer> map = new HashMap<String, Integer>() {
{
put("Ling", 0);
put("Yi", 1);
put("Er", 2);
put("San", 3);
put("Si", 4);
put("Wu", 5);
put("Liu", 6);
put("Qi", 7);
put("Ba", 8);
put("Jiu", 9);
put("Shi", 10);
put("Bai", 100);
put("Qian", 1000);
put("Wan", 10000);
put("Yii", 100000000);
}
};
Scanner in = new Scanner(System.in);
System.out.println("请输入:");
String line = in.nextLine();
// 赋值
for (int i = 0; i < line.length();) {
String str1 = "";
str1 = line.substring(i, i + 1);
String str2toKey = "";
char[] chars = new char[4];
chars[0] = str1.charAt(0);
i++;//add here
if (chars[0] >= 'A' && chars[0] <= 'Z') {
int j = 0;
while (j < 3 && (line.substring(i, i + 1)).charAt(0) >= 'a'
&& (line.substring(i, i + 1)).charAt(0) <= 'z') {
chars[++j] = (line.substring(i, i + 1)).charAt(0);
i++;
if (i == line.length()){ //add a guard, or will exception
break;
}
}
// 判断 chars是否是大写
str2toKey= String.valueOf(chars); // 保存一串字母
mapint.put(count++, map.get(str2toKey.trim()));// 保存对应的数字
//System.out.println(mapint.get(count-1));
}
}
for(int i=0;i<mapint.size();i=i+2){
if(mapint.get(i) == 0){
sum+=mapint.get(i+1);
}
else {
if(i+1 != mapint.size()){
sum=sum+mapint.get(i)*mapint.get(i+1);
}
else{
sum+=mapint.get(i);
}
}
}
System.out.println("转换后: \n"+sum);
}
}