好不容易看懂了一道题,却不会做!!! 题解代码越看越有味道,越想与有道理!!!
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char wei[100][100]= {"Shi","Bai","Qian","Wan","Yi"};
char num[100][100]= {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int main()
{
char str[51];
scanf("%s",str);
int len=strlen(str);
int left=0,right=len-1;
if(str[0]=='-')
{
printf("Fu");
left++;
}
while(left+4<=right)
{
right-=4;
}
while(left<len)
{
int flag=0;
int isPrint=0;
while(left<=right)
{
if(str[left]=='0'&&left>0)
{
flag=1;
}
else
{
if(flag==1)
{
printf(" ling");
flag=0;
}
if(left>0) printf(" ");
printf("%s",num[str[left]-'0']);
isPrint=1;
if(left!=right)
{
printf(" %s",wei[right-left-1]);
}
}
left++;
}
if(isPrint==1&&right!=len-1)
{
printf(" %s",wei[(len-1-right)/4+2]);
}
right+=4;
}
return 0;
}
|