PAT-1005 Spell It Right

题目

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

 

上一篇:小程序


下一篇:微信小程序笔记