1002 写出这个数 (20分)
读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:
每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10^100
输出格式:
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
代码展示:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10
/* run this program using the console pauser or add your own getch,
system("pause") or input loop */
typedef struct{
char c[10];
}Han;
int main(int argc, char *argv[]) {
Han han[10];
strcpy(han[0].c,"ling");strcpy(han[1].c,"yi");strcpy(han[2].c,"er");
strcpy(han[3].c,"san");strcpy(han[4].c,"si");strcpy(han[5].c,"wu");
strcpy(han[6].c,"liu");strcpy(han[7].c,"qi");strcpy(han[8].c,"ba");
strcpy(han[9].c,"jiu");
char a[1000];
scanf("%s",&a);
int n=strlen(a);
int i,t,sum=0;
for(i=0;i<n;i++){
t=a[i]-'0';
sum+=t;
}
int s[N];int top=0; //定义栈结构
while(sum!=0){
n=sum%10;
sum=sum/10;
s[top]=n;top++;
}
while(top>0){
top--;
printf("%s",han[s[top]].c);
if(top>0){
printf(" ");
}
}
return 0;
}