PAT (Advanced Level) Practice 1082 Read Number in Chinese (25 分)
阿新 • • 發佈:2018-11-26
有點變態的模擬啊- =
#include<cstdio>
#include<cstring>
using namespace std;
const int N=20+5;
char ss[N];
char name[][10]={"",""," Shi"," Bai"," Qian"," Wan"," Shi"," Bai"," Qian"," Yi"};
char num[][10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int main()
{
scanf("%s" ,ss);
int len=strlen(ss);
int i=0;
while(i<len&&ss[i]=='0') i++;
if(i==len) printf("ling");
else
{
for(int j=0;i<len;i++)
{
if(ss[i]=='-') j++,printf("Fu");
else if(ss[i]!='0')
{
if(j) printf(" ");
printf ("%s%s",num[ss[i]-'0'],name[len-i]);
j++;
}
else
{
int k=i;
while(k<len&&ss[k]=='0') k++;
if(k!=len)
{
if(j) printf(" ");
if(len-i>= 5&&len-k<5) printf("Wan ");
printf("ling");
j++;
}
else
{
if(len-i>=5&&len-k<5)
{
if(j) printf(" ");
printf("Wan");
j++;
}
}
i=k-1;
}
}
}
printf("\n");
return 0;
}