读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。 输出格式:在一行内输出n的各位数字之和

// ConsoleApplication95.cpp : 定义控制台应用程序的入口点。
//


#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
int n, i, j = 10, m = 0;
string st[100];
cout << "请输入一个小于10^10的随机整数:";
cin >> n;
while (n>0)
{
i = n%j;
n = n / 10;
m = m + i;
}
int h = 0;
while (m>0)
{
int k = m%j;
switch (k)
{
case 1:
st[h] = "yi";
cout<< " ";
break;
case 2:
st[h] = "er";
cout<< " ";
break;
case 3:
st[h] = "san";
cout<< " ";
break;
case 4:
st[h] = "si";
cout<< " ";
break;
case 5:
st[h] = "wu";
cout<< " ";
break;
case 6:
st[h] = "liu"; 
cout << " ";
break;
case 7:
st[h] = "qi";
cout << " ";
break;
case 8:
st[h] = "ba";
cout << " ";
break;
case 9:
st[h] = "jiu";
cout << " ";
break;
default:
st[h] = "ling";
cout << " ";
break;
}
m = m / 10;
h++;
}
h = h - 1;
while (h >= 0)
{
cout << st[h] << " ";
h--;
}
}

猜你喜欢

转载自blog.csdn.net/CAUC_yangxiao/article/details/78373858