关键:字符串问题,注意边界0的处理,各种特殊情况
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
char change[11][10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
char wei[5][5]={"Shi","Bai","Qian","Wan","Yi"};
char str[15];
gets(str);
int len=strlen(str);
int left=0,right=len-1;
if(str[0]=='-'){
cout<<"Fu";
left++;
}
while(left+4<=right){
right-=4;
}
while(left<len){
bool flag=false;
bool isPrint=false;
while(left<=right){
if(left>0 && str[left]=='0'){
flag=true;
}else{
if(flag==true){
printf(" ling");
flag=false;
}
if(left>0) printf(" ");
printf("%s",change[str[left]-'0']);
isPrint=true;
if(left!=right){
printf(" %s",wei[right-left-1]);
}
}
left++;
}
if(isPrint=true && right!=len-1){
printf(" %s",wei[(len-right-1)/4+2]);
}
right+=4;
}
return 0;
}