PAT 甲级 1082 Read Number in Chinese
作者:
自由基
,
2021-07-29 09:00:10
,
所有人可见
,
阅读 261
输入样例
-123456789
输出样例
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
C++代码
#include<cstdio>
#include<cstring>
char num[10][5] = {
"ling","yi","er","san","si","wu","liu","qi","ba","jiu"
};
char wei[5][5] = {"Shi", "Bai", "Qian", "Wan", "Yi"};
int main ( ) {
char s[15];
scanf("%s", s );
int len = strlen(s);
int l = 0, r = len - 1;
if ( s[0] == '-' ) {
printf("Fu");
l++;
}
while ( l + 4 <= r ) {
r -= 4;
}
while ( l < len ) {
bool flag = false;
bool isprint = false;
while ( l <= r ) {
if( l > 0 && s[l] == '0' ) {
flag = true;
}
else {
if ( flag == true ) {
printf(" ling");
flag = false;
}
if ( l > 0 ) printf(" ");
printf("%s", num[s[l] - '0']);
isprint = true;
if ( l != r ) {
printf(" %s", wei[r - l - 1]);
}
}
l++;
}
if ( isprint == true && r != len - 1 ) {
printf(" %s", wei[( len - 1 - r ) / 4 + 2]);
}
r += 4;
}
return 0;
}