PAT-1005 Spell It Right

题目

 代码

 

#include <bits/stdc++.h>
using namespace std;
string s[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int a[1000];
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    string in;
    cin>>in;
    int sum=0;
    for(int i=0;i<in.size();i++){
        sum+=in[i]-'0';
    }
    int index=0;
    while(sum){
        a[index++]=sum%10;
        sum/=10;
    }
    for(int i=index-1;i>=1;i--){
        cout<<s[a[i]]<<" ";
    }
    cout<<s[a[0]]<<endl;
    return 0;
}

 

posted @ 2020-12-13 13:26  grass_lin  阅读(35)  评论(0编辑  收藏  举报