本文主要是介绍pat 1082. Read Number in Chinese 整数串和字符串转化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
其实也水,但是要考虑的东西还是不少
1.大于一万的数肯定会读一次wan
2.亿位,万位和个位都不读零
3.多个零只读一次
4.尾数零不读
3.注意控制空格,尤其是有连续多个0时
测试用例:101010101
正解:yi Yi ling yi Bai ling yi Wan ling yi Bai ling yi
#include<stdio.h>
int arr[9];
char brr[9][5]={"Yi","Qian","Bai","Shi","Wan","Qian","Bai","Shi"};
char crr[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
void output(int i,int x)
{static int l=0;static int flag=0;if(x){if(l++)printf(" ");if(flag)printf("ling ");flag=0;if(i<8)printf("%s %s",crr[x],brr[i]);elseprintf("%s",crr[x]);}else{if(i==4){printf(" Wan");flag=0;return;}if(i==8){return;} flag=1;}
}int main()
{int x,i,j;scanf("%d",&x);int arr[9];if(x<0){x=-x;printf("Fu "); }if(x==0){printf("ling\n");return 0;}for(i=0,j=100000000;i<9;i++,j/=10){arr[i]=(x/j)%10;}for(i=0;i<9;i++){if(arr[i]!=0)break;}for(;i<9;i++){output(i,arr[i]);}printf("\n");return 0;
}
这篇关于pat 1082. Read Number in Chinese 整数串和字符串转化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!