说真的这道题按照算法笔记上写应该会比较简单,能完美避免末尾0的问题。但是我就是头铁,就是要从头到尾的进行处理,事实证明难是不难,就是要考虑的内容太多
#include <iostream>
#include <cstdio>
#include <cstring>
#include<iostream>
#include <string.h>
using namespace std;
int main(){
int start=0;
bool istotoal=true;
char w[][11] = {"Yi","Qian","Bai","Shi","Wan","Qian","Bai","Shi",""};
char n[][11] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
char str[15];
cin.getline(str,15);
int length=strlen(str);
if(length==1 && str[0]=='0'){
printf("ling");
return 0;
}
if(str[0]=='-'){
printf("Fu");
start=1;
}
int shulen=length-start;
for(int i=start;i<length;i++){
if(str[i]=='0'){
if(i==length-5 && istotoal==false)printf(" Wan");
while(str[i+1]=='0'&& (i+1)!=length-1 && (i+1)!=length-5){
i++;
}
if(((i+1)==length-5 && str[i+1]=='0')||((i+1)==length-1 && str[i+1]=='0')||i==length-1||i==length-5){
}else{
printf(" ling");
}
//if((i+1)==length-5 && istotoal==false){
//printf(" Wan");
//}
}else{
if(i==length-1){
int curnum=str[i]-'0';
if(i>0)printf(" ");
printf("%s",n[curnum]);
}else{
int curnum=str[i]-'0';
if(i<length-5 && length-i!=9)istotoal=false;
if(i>0)printf(" ");
printf("%s %s",n[curnum],w[8-length+1+i]);
}
}
}
return 0;
}
当然AC是肯定的
image.png
网友评论