解题思路:
好麻烦,好吧,做了一个半小时,最后还运行错误了,去官网测数据才发现有很多小小的细节你改变了一个另一个细节就gg了,难度不大,但是超级烦
注意事项:
十的判断
0的判断
参考代码:
#include<cstdio>
#include<string>
#include <map>
#include <iostream>
using namespace std;
string num[10] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
string cha[50];
int cur = 0;
void zuzhuang(int m);
void output(int m);
int main()
{
int num;
scanf("%d",&num);
zuzhuang(num);
for(int i = cur-1; i >= 0; i--){
if(i >= 3) if(i == cur-2 && cha[i-1] == "shi") continue;
if(i == cur-1 && cha[i] == "ling") continue;
if(i) cout << cha[i] << " ";
else cout << cha[i];
}
return 0;
}
void zuzhuang(int m){
int len = 0;
int zu[3];
while(m){
zu[len++] = m%10000;
m /= 10000;
}
if(len == 0){ printf("ling"); return ;}
if(zu[0]) output(zu[0]);
if(zu[1]) if(len >= 2){cha[cur++] = "wan"; output(zu[1]);}
if(zu[2]) if(len >= 3){cha[cur++] = "yi"; output(zu[2]);}
}
void output(int m){
int q = 0,b = 0,s = 0,g = 0;
g = m%10; s = m/10%10; b = m/100%10; q = m/1000;
if(g){cha[cur++] = num[g];}
if(s){cha[cur++] = "shi"; cha[cur++] = num[s];}
else if(!g) {}
else cha[cur++] = num[s];
if(b){cha[cur++] = "bai"; cha[cur++] = num[b];}
else if(g == 0 && s == 0) {}
else if(cha[cur-1] == "ling") {}
else cha[cur++] = num[b];
if(q){cha[cur++] = "qian"; cha[cur++] = num[q];}
else if(cha[cur-1] == "ling") {}
else cha[cur++] = num[q];
}
0.0分
0 人评分