天天看点

1005. Spell It Right (20)

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int sum = 0, len = (int)s.length();
    
    for (int i = 0; i < len; i++) {
        sum += s[i] - '0';
    }
    
    string sp = to_string(sum);
    string num[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    
    cout << num[sp[0] - '0'];
    for (int i = 1; i < sp.length(); i++) {
        cout << ' ' << num[sp[i] - '0'];
    }
    
    cout << endl;
   
    return 0;
}