1002.写出这个数

这里写图片描述

#include "stdafx.h"

string num_table[] = { "ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };                //将每个数字对应的拼音保存在数组里

string  wrt(int n)
{
    string str = num_table[n];
    return str;
}

int _tmain(int argc, _TCHAR* argv[])
{
    char num_1;                                        //因为输入的数可能很大,所以用char型来保存每一位防止溢出
    int i = 0;
    int cnt = 0;
    while ((num_1 = getchar()) != '\n')                 //一直输入,直到遇到回车
    {
        cnt += (num_1 - '0');                            //char型减去‘0’直接就是数字

    }
    int temp = 0;
    deque<string> str;                                    //使用deque型容器,方便每次将新数插入开头
    while (cnt)
    {
        temp = cnt % 10;
        str.push_front(wrt(temp));
        cnt /= 10;
    }
    for (auto i = str.cbegin(); i != str.cend(); ++i)
    {
        if (i == str.cend() - 1)
        {
            cout << *i;
        }
        else
            cout << *i << ' ';
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值