1002 写出这个数 (20 分)
思路:首先求和,再把各位的和转换为字符串,最后用数字映射出对应的拼音。
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] strs = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
char[] chr = str.toCharArray();
int sum =0;
for(char c :chr){
int x = c - '0';
sum = sum + x;
}
String sums = String.valueOf(sum);
char[] chars = sums.toCharArray();
StringBuilder sb = new StringBuilder();
for(char c : chars){
int x = c -'0';
sb.append(strs[x] + ' ');
}
sb.deleteCharAt(sb.length() -1);
System.out.print(sb.toString());
}
}
PAT乙级 文章被收录于专栏
做题记录