读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:
每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10100。
输出格式:
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
结尾无空行
输出样例:
yi san wu
结尾无空行
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
Scanner sc = new Scanner(System.in);
String n = sc.next();
int num = 0;
for (int i = 0; i < n.length(); i++) {
num += n.charAt(i) - '0';
}
String ns = getChinese(num);
System.out.println(ns);
}
static String getChinese(int num){
String str = String.valueOf(num);
String[] split = str.split("");
String result = "";
for (int i = 0; i < split.length; i++) {
switch (split[i]){
case "0":
result += "ling";
if (i!=split.length-1){
result += " ";
}
break;
case "1":
result += "yi";
if (i!=split.length-1){
result += " ";
}
break;
case "2":
result += "er";
if (i!=split.length-1){
result += " ";
}
break;
case "3":
result += "san";
if (i!=split.length-1){
result += " ";
}
break;
case "4":
result += "si";
if (i!=split.length-1){
result += " ";
}
break;
case "5":
result += "wu";
if (i!=split.length-1){
result += " ";
}
break;
case "6":
result += "liu";
if (i!=split.length-1){
result += " ";
}
break;
case "7":
result += "qi";
if (i!=split.length-1){
result += " ";
}
break;
case "8":
result += "ba";
if (i!=split.length-1){
result += " ";
}
break;
case "9":
result += "jiu";
if (i!=split.length-1){
result += " ";
}
break;
}
}
return result;
}
}