7-25 念数字 (15分)
程序员文章站
2022-06-08 13:24:10
...
/思路:用const char*/
代码如下:
#include<stdio.h>
int main()
{
const char *s[11] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
char c;
int flag = 0;
scanf("%c", &c);
while (c != '\n')
{
if (c == '-')
{
printf("fu"); flag = 1;
}
else
{
if (flag == 0)
{
printf("%s", s[c - '0']);
flag = 1;
}
else if (flag == 1)
printf(" %s", s[c - '0']);
}
scanf("%c", &c);
}
return 0;
}