PAT甲级1005,字符串

#include
using namespace std;

int main(){
    string str[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    string t;
    cin>>t;
    int sum=0;
    for(int i=0;i<t.length();i++)
        sum+=t[i]-'0';
    string s=to_string(sum);
    for(int i=0;i<s.length();i++){
        if(i!=0)cout<<" ";
        cout<<str[s[i]-'0'];
    }

    return 0;
}

你可能感兴趣的:(PAT甲级)