Coder

舒心、快乐,比什么都重要

1002 写出这个数 (20 分)

#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main(){
    int sum = 0;
    string num;
    stack<int>number;
    string str[10] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
    cin >> num;
    for (int i = 0; i < num.size(); i++){
        sum += num[i] - '0';
    }
    while (sum != 0){
        number.push(sum % 10);
        sum /= 10;
    }
    while (!number.empty()){
        cout << str[number.top()];
        number.pop();
        if (!number.empty()){
            cout << ' ';
        }
        else{
            cout << endl;
        }
    }
    return 0;
}

 

posted @ 2019-04-15 21:05  H123K  阅读(115)  评论(0编辑  收藏  举报