7-23 币值转换(20 分)

7-23 币值转换(20 分)

输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式。如23108元,转换后变成“贰万叁仟壹百零捌”元。为了简化输出,用小写英文字母a-j顺序代表大写数字0-9,用S、B、Q、W、Y分别代表拾、百、仟、万、亿。于是23108元应被转换输出为“cWdQbBai”元。

输入格式:

输入在一行中给出一个不超过9位的非负整数。

输出格式:

在一行中输出转换后的结果。注意“零”的用法必须符合中文习惯。

输入样例1:

1
813227345

输出样例1:

1
iYbQdBcScWhQdBeSf

输入样例2:

1
6900

输出样例2:

1
gQjB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>

int main(){
char a[10]={'a','b','c','d','e','f','g','h','i','j'};
char b[10]={'0','S','B','Q','W','S','B','Q','Y'};
int c[10]={0};
int flag[10]={1,1,1,1,1,1,1,1,1,1,};
long n;
int len=0;
scanf("%ld",&n);
long t=n;
int j;
int hou=0;
while(t>0){
c[len]=t%10;
t/=10;
len++;
}
if(n==0) printf("a");
else{
for(j=0;j<len;j++){
if(c[j]==0){
flag[j]=0;
}
else break;
}
for(j=len-1;j>=0;j--){
if(j==len-1){
if(len==1){
printf("%c",a[c[j]]);
break;
}
else if(flag[j]==1&&flag[j-1]==0){
printf("%c%c",a[c[j]],b[j]);
if(j==8||j<=4) break;
else if(j>4&&j<8){
printf("W");
break;
}
}
else printf("%c%c",a[c[j]],b[j]);
}
else if(j>4){
if(c[j]!=0&&flag[j]==1&&flag[j-1]==0){
printf("%c%cW",a[c[j]],b[j]);
break;
}
else if(c[j]!=0) printf("%c%c",a[c[j]],b[j]);
else if(c[j]==0&&c[j-1]!=0) printf("a");
}
else if(j==4){
if(c[j]!=0&&flag[j]==1&&flag[j-1]==0){
printf("%c%c",a[c[j]],b[j]);
break;
}
else if(c[j]!=0) printf("%c%c",a[c[j]],b[j]);
else if(c[j]==0&&c[j-1]!=0) printf("Wa");
}
else if(j<4&&j>0){
if(c[j]!=0&&flag[j]==1&&flag[j-1]==0){
printf("%c%c",a[c[j]],b[j]);
break;
}
else if(c[j]!=0) printf("%c%c",a[c[j]],b[j]);
else if(c[j]==0&&c[j-1]!=0) printf("a");
}
else if(j==0){
printf("%c",a[c[j]]);
}
}
}
return 0;
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×