读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
#include<stdio.h>
#include<string.h>
int main(){
char s[];
scanf("%s",s);
int n = strlen(s);
int sum=;
int i = ;
while(n--)
{
sum = sum + s[i]-'';
i++;
}
i = ;
int a[];
while(sum)
{
a[i] = sum%;
sum = sum/;
i++;
}
char c[][] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
i--;
printf("%s",c[a[i]]);
while(i--)
{
printf(" %s",c[a[i]]);
}
}
python
a ,sum = input(),0
for i in a:sum += int(i)
b = ['ling','yi','er','san','si','wu','liu','qi','ba','jiu']
c = [b[int(i)] for i in str(sum)]
print(c[0],end='')
for i in range(1,len(c)):print(' {0}'.format(c[i]),end='')