int chineseToNumber(char *str) { // 映射表 char *digits[] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}; char *units[] = {"", "十", "百", "千"}; int values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000}; int result = 0; int temp = 0; int i; for (i = 0; str[i] != '\0'; i++) { int found = 0; for (int j = 0; j <10; j++) { if (strcmp(digits[j], &str[i]) == 0) { temp = values[j]; found = 1; break; } } if (!found) { for (int j = 0; j <4; j++) { if (strcmp(units[j], &str[i]) == 0) { if (j == 0) { result += temp; } else { result += temp * values[j + 9]; } temp = 0; found = 1; break; } } } if (!found) { printf("Invalid character: %s\n", &str[i]); return -1; } } result += temp; return result; }
int main() { char input[] = "一万两千三百四十五"; int number = chineseToNumber(input); if (number != -1) { printf("The number is: %d\n", number); } return 0; } ```
Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ...
[详细]