1005 Spell It Right (20 分)

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int inf = 0x3fffffff;
const int maxn = 110;

int main(){
    string str;
    string match[] = {"zero", "one", "two", "three", "four",
                      "five","six", "seven","eight", "nine"};
    cin >> str;
    int sum = 0;
    for(int i = 0; i < str.size(); i++){
        sum += str[i] - '0';
    }
    if(sum == 0){
        cout << "zero" << endl; return 0;
    }
    int res[100], top = -1, c = 0;
    while(sum > 0){
        res[++top] = sum%10;
        sum /= 10;
    }
    int flag = 1;
    while(top >= 0){
        if(!flag) cout << " ";
        cout << match[res[top--]];
        flag = 0;
    }putchar('\n');
}

 

你可能感兴趣的:(PAT)