1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() { 4 char a[100]; 5 cin >> a; 6 string b[10] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"}; 7 string c[11] = {"", "", "shi", "bai", "qian", "wan", "shi", "bai", "qian", "yi", "shi"}; 8 int l = strlen(a); 9 for (int i = 0; i < l; i++) { 10 int j = a[i] - ‘0‘; 11 if (j != 0) { 12 if (((l - i == 2) || (l - i == 6) || (l - i == 10)) && j == 1) { 13 if (i != 0) { 14 cout << "yi "; 15 } 16 cout << "shi "; 17 continue; 18 } 19 cout << b[j] << " "; 20 cout << c[l - i] << " "; 21 } else { 22 if (l - i == 5 || l - i == 9) { 23 cout << c[l - i] << " "; 24 } 25 if (a[i + 1] == ‘0‘ || i == l - 1) { 26 continue; 27 } 28 cout << "ling" << " "; 29 } 30 } 31 return 0; 32 }
原文:https://www.cnblogs.com/fx1998/p/12807083.html