1002.写出这个数

来源:互联网 发布:淘宝有哪些奇葩商品 编辑:程序博客网 时间:2024/05/16 14:59

这里写图片描述

#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
原创粉丝点击