随手写了一个,没怎么测,你试试吧
/*
Create by ABacker on 12/04/2017
[0,100000)金额读法
*/
#include
int main() {
const char *s[] = {
"wan","qian","bai","shi",""
};
const int div[] = {
10000,1000,100,10,1
};
int n;
scanf("%d", &n);
if (n == 0) {
printf("0");
}
int quo;
bool zero = true;
for (int i = 0; i < 5; ++i) {
quo = n / div[i];
n -= quo*div[i];
if (quo == 0) {
if (zero == false && n > 0) {
printf("0");
}
zero = true;
}
if (quo > 0) {
printf("%d%s", quo, s[i]);
zero = false;
}
}
printf("\n");
return 0;
}