读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:1234567890987654321123456789输出样例:
yi san wu
AC代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[] arr = new int[1000];
int count = 0;
Scanner in = new Scanner(System.in);
String n = in.nextLine();
int sum = 0;
for(int i = 0; i<n.length(); i++){
sum = sum + (n.charAt(i) - 48);
}
while(sum != 0){
arr[count] = qiuyu(sum);
sum = sum / 10;
count++;
}
if(count == 1) sw(arr[0]);
else{
for(int i = count-1;i>=0;i--){
sw(arr[i]);
if(i!=0) System.out.print(" ");
}
}
}
public static int qiuyu(int s){
int yu = 0;
yu = s % 10;
return yu;
}
public static void sw(int a){
switch (a) {
case 0:
System.out.print("ling");
break;
case 1:
System.out.print("yi");
break;
case 2:
System.out.print("er");
break;
case 3:
System.out.print("san");
break;
case 4:
System.out.print("si");
break;
case 5:
System.out.print("wu");
break;
case 6:
System.out.print("liu");
break;
case 7:
System.out.print("qi");
break;
case 8:
System.out.print("ba");
break;
case 9:
System.out.print("jiu");
break;
}
}
}