读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu 思路:正常模拟, #include<string.h> strlen strcmp strcpy
1 #include<stdio.h> 2 #include<string.h> 3 char str[11000]; 4 5 char number[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; 6 7 int main(int argc, char* argv[]) 8 { 9 while(scanf("%s",str)!=EOF) 10 { 11 int sum=0; 12 int length=strlen(str); 13 int i; 14 for(i=0;i<length;i++) 15 { 16 sum+=str[i]-48; 17 } 18 int ge,shi,bai,qian,wan; 19 wan=sum/10000; 20 qian=sum%10000/1000; 21 bai=sum%1000/100; 22 shi=sum%100/10; 23 ge=sum%10; 24 if(wan!=0) 25 printf("%s %s %s %s %s\n",number[wan],number[qian],number[bai],number[shi],number[ge]); 26 else if(qian!=0) 27 printf("%s %s %s %s\n",number[qian],number[bai],number[shi],number[ge]); 28 else if(bai!=0) 29 printf("%s %s %s\n",number[bai],number[shi],number[ge]); 30 else if(shi!=0) 31 printf("%s %s\n",number[shi],number[ge]); 32 else 33 printf("%s\n",number[ge]); 34 } 35 return 0; 36 }
时间: 2024-11-13 14:08:25