我自行用隨機數測試10000次沒問題,
請問為什麼會RE呢?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *chineseA[] = {"","壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖"};
char *chineseB[] = {"仟", "", "拾", "佰"};
char *chineseC[] = {"", "萬", "億", "兆", "京"};
int divisorTable[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
int getMedian(int input) {
int amount = 1;
while(1) {
input = input / 10;
if(input < 1) break;
amount++;
}
return amount;
}
int getDivisor(int n) {
int result = 1;
int index = 0;
for (; index < n; index++) {
result = result * 10;
}
return result;
}
int main(void) {
int input;
while(scanf("%d\n", &input) != 0) {
int hasZeroBefore = 0;
int isNeedPrintChineseC = 0;
int length = getMedian(input);
int index;
for(index = 0; index < length; index++) {
int divisot = divisorTable[(length - 1 - index)];
int tempNum = input / divisot;
input = input - tempNum * divisot;
int lengthSubI = length - index;
if(tempNum != 0) {
isNeedPrintChineseC = 1;
if(hasZeroBefore == 1) {
printf("零");
hasZeroBefore = 0;
}
printf("%s", chineseA[tempNum]);
printf("%s", chineseB[lengthSubI % 4]);
} else {
hasZeroBefore = 1;
}
if(isNeedPrintChineseC == 1 && lengthSubI % 4 == 1) {
printf("%s", chineseC[lengthSubI / 4]);
isNeedPrintChineseC = 0;
}
}
if(length == 1 && hasZeroBefore == 1) printf("零");
printf("\n");
}
return 0;
}