题目:
读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:
每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10^100。
输出格式:
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
代码长度限制 16 KB
时间限制 400 ms
内存限制 64 MB
基本步骤:
#include
using namespace std;
void Print1(int x)
{
switch (x)
{
case 1:
cout << "yi";
break;
case 2:
cout << "er";
break;
case 3:
cout << "san";
break;
case 4:
cout << "si";
break;
case 5:
cout << "wu";
break;
case 6:
cout << "liu";
break;
case 7:
cout << "qi";
break;
case 8:
cout << "ba";
break;
case 9:
cout << "jiu";
break;
case 0:
cout << "ling";
break;
}
}
void Print2(int x)
{
if (x)
{
Print2(x / 10);
if (x > 9)
{
cout << " ";
}
Print1(x % 10);
}
}
int main()
{
char arr[101] = {0};
cin >> arr;
int i = 0;
long long sum = 0;
while (arr[i])
{
sum += (arr[i] - '0');
i++;
}
Print2(sum);
return 0;
}