简单的操作题,不要忘了sum为0的情况。
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int sum;
string num2word[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
stack<string> ans;
void read()
{
char c;
while((c = getchar()) != '\n')
{
sum += (c - '0');
}
}
void solve()
{
if(!sum)
ans.push(num2word[0]);
while(sum)
{
ans.push(num2word[sum%10]);
sum /= 10;
}
}
void print()
{
cout << ans.top();
ans.pop();
while(!ans.empty())
{
cout << ' ' << ans.top();
ans.pop();
}
}
int main()
{
read();
solve();
print();
return 0;
}