#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;
}
1002.写出这个数
最新推荐文章于 2021-01-29 20:28:55 发布