题解 | #学英语#

字典法
#include <bits/stdc++.h>
using namespace std;

int main(){
    string a[]= {"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourtenn","fifteen","sixteen","seventeen", "eighteen", "nineteen"};
    string b[]= {"","","twenty", "thirty", "forty", "fifty", "sixty","seventy", "eighty", "ninety"};
    string c[]= {"","thousand","million","billion"};
    long n;
    int m,l;
    string s,t,r;
    cin>> n;
    s= to_string(n);
    m= (s.length()-1)/ 3;
    l= s.length()% 3;
    if(l!= 0)
        for(int i= 0; i< 3-l; ++i)
            t+= '0';
    t+= s;
    s.clear();
    for(int i =m; i>= 0; --i){
        for(int j=0; j< 3; ++j){
            s+= t[j];
            r+= t[j];
        }
        r= r.substr(1);
        t= t.substr(3);
        if(s[0]!= '0')
            if( stoi(r)!= 0)
                cout<< a[s[0]-'0']<< " hundred and ";
            else
                cout<< a[s[0]-'0']<< " hundred ";
        if(s[1]>= '2')
            if(s[2]- '0'!= 0)
                cout<< b[ s[1]- '0' ]<< " "<< a[s[2]- '0' ]<< " ";
            else
                cout<< b[ s[1]- '0' ]<< " ";
        else
            cout<< a[ stoi(r) ]<< " ";
        cout<< c[i]<< " ";
        s.clear();
        r.clear();
    }
}


全部评论

相关推荐

Aurora23:属于挂一半,暂时进池子了,隔一段时间没有其他组捞的话就彻底结束了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务