Python解法1:
numbers = input()
sum = 0
for number in numbers:
sum = sum + int(number)
strsums = str(sum)
info = []
for strsum in strsums:
if strsum == '1':
info.append("yi")
elif strsum == '2':
info.append("er")
elif strsum == '3':
info.append("san")
elif strsum == '4':
info.append("si")
elif strsum == '5':
info.append("wu")
elif strsum == '6':
info.append("liu")
elif strsum == '7':
info.append("qi")
elif strsum == '8':
info.append("ba")
elif strsum == '9':
info.append("jiu")
else:
info.append("ling")
result = ''
i = 0
while i < len(info) - 1:
result = result + info[i] + ' '
i = i + 1
result = result + info[-1]
print(result)
Python解法2:
dic = {"0": "ling", "1": "yi", "2": "er", "3": "san", "4": "si", "5": "wu", "6": "liu", "7": "qi", "8": "ba", "9": "jiu"}
print(" ".join(map(lambda c: dic[c], str(sum(map(int, input()))))))
Python解法3:
s0= input()
sum=0
for c in s0:
sum+=int(c)
tmp={'0':'ling','1':'yi','2':'er','3':'san','4':'si','5':'wu','6':'liu','7':'qi','8':'ba','9':'jiu'}
lst=[tmp[c] for c in str(sum)]
s1=' '.join(lst)
print(s1)
Java:
import java.util.Scanner;
public class Test_1002 {
public static void main(String[] agrs) {
Scanner sc=new Scanner(System.in);
String s=sc.next();
int sum=0;
for(int i=0;i<s.length();i++) {
sum+=(s.charAt(i)-'0');
}
String str=String.valueOf(sum);
for(int i=0;i<str.length();i++) {
change(str.charAt(i));
if(i<str.length()-1) {
System.out.print(" ");
}
}
}
static void change(char c) {
switch(c) {
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;
}
}
}