注意:如果你按照视频中的代码去pat官网测试的会因为格式不对而一分不得,主要原因是最后输出的时候会有多余的空格所以需要特判一下
原题链接:PAT甲级1005
练练手:PAT乙级1002
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
string n[] = {
"zero","one","two","three","four","five","six","seven","eight","nine"
};
int main()
{
string num; cin >> num;
int sum = 0;
for (auto c : num) sum += c - '0';
string res = to_string(sum);
for (int i = 0; i < res.size(); i ++)
{
if (i == 0) cout << n[res[i] - '0'];
else cout << ' ' << n[res[i] - '0'];
}
return 0;
}