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;
}


上一篇:1002. A+B for Polynomials (25)


下一篇:1003 Emergency (25)