美文网首页PAT (Advanced Level) Practice
1005 Spell It Right (20point(s))

1005 Spell It Right (20point(s))

作者: iphelf | 来源:发表于2020-02-28 00:18 被阅读0次

    过于简单。不解释。

    #include<cstdio>
    #include<iostream>
    #include<stack>
    #include<string>
    using namespace std;
    
    string word[]={
        "zero","one","two","three","four",
        "five","six","seven","eight","nine"
    };
    
    int main(void) {
    //    freopen("in.txt","r",stdin);
        string n;
        cin>>n;
        int sum=0;
        for(int i=0;i<n.size();i++) sum+=n[i]-'0';
        if(sum==0){
            cout<<"zero"<<endl;
            return 0;
        }
        stack<int> s;
        while(sum>0){
            s.push(sum%10);
            sum/=10;
        }
        while(!s.empty()){
            cout<<word[s.top()];
            s.pop();
            if(s.empty()) cout<<endl;
            else cout<<' ';
        }
        return 0;
    }
    
    /*
    Sample Input:
    12345
    
    Sample Output:
    one five
    */
    

    相关文章

      网友评论

        本文标题:1005 Spell It Right (20point(s))

        本文链接:https://www.haomeiwen.com/subject/acyqhhtx.html