#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; }
标签:index,10,int,sum,long,num,第五天,随笔 From: https://www.cnblogs.com/kuandong24/p/17334370.html