看了半天才明白题意😂,12345每位之和为1+2+3+4+5 = 15,用英文表达为one five。
#include <iostream>
#include <algorithm>
using namespace std;
char word[][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main()
{
string s; //高精度数字用字符串储存
cin >> s;
int n = 0;
for (auto c : s) n += c - '0'; //遍历字符串,累加每一位数
s = to_string(n); //数字转换为字符串
for (int i = 0; i < s.size(); i ++ )
{
cout << word[s[i] - '0'] << ' ';
}
return 0;
}