发现没有题解,我来水一篇题解…
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
string table[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main()
{
string a;
cin >> a;
if(a == "0") //特判,不然遇到0会段错误
{
cout << "zero";
return 0;
}
long long sum = 0;
int ans[10000];
int len = a.length();
for (int j = 0; j < len; j++)
{
sum += (a[j] - '0');
}
int i = 0;
while(sum)
{
ans[i] = sum % 10;
sum /= 10;
i++;
}
i--;
while(i)
{
cout << table[ans[i]] << " ";
i--;
}
cout << table[ans[i]]; //末尾不能有空格
return 0;
}
前排%%%%%%%%%%%