PTA 1005 Spell It Right

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dpdpd/article/details/82119348

题意:输入数字,计算总和并输出英文拼音
注意点:
1、不要有英语拼写错误
2、0的时候输出为0

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    long long int tmp=0;
    for(int i=0;i<s.size();i++){
        tmp+=(s[i]-'0');
    }
    string match[11]={"zero","one","two","three","four","five","six","seven","eight","nine","ten"};
    vector<string> v;
    long long int sum=tmp;
    while(sum){
        v.push_back(match[sum%10]);
        sum/=10;
    }

    reverse(v.begin(),v.end());
    if(tmp==0)//当n为0的时候 
    cout<<"zero\n";
    else
    for(int i=0;i<v.size();i++){
        if(i==0)
        cout<<v[i];
        else
        cout<<" "<<v[i];
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/dpdpd/article/details/82119348