第五天随笔
#include <iostream> #include <string> using namespace std; int main() { string pingyin[10] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; string num; long long int index[100] = {0}; // 将数组元素全部初始化为 0 long long int sum = 0; cin >> num; for (int i = 0; i < num.length(); i++) { sum += num[i] - '0'; // 将字符型数字转化为整型数字累加 } int k = 0; while (sum != 0) { index[k] = sum % 10; sum /= 10; k++; } for (int i = 99; i >= 0; i--) { if (index[i] != 0) { if (i == 0) { cout << pingyin[index[i]]; } else { cout << pingyin[index[i]] << " "; } } } return 0; }