#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
string numbers;
cin >> numbers;//把所有位上的数字都储存在字符串里头
unsigned int sum = 0;
for (auto a : numbers)
sum = a + sum - 48;//sum计算所有位上的数字之和
//注意减去四十八是因为零到九的数字的ASCII码比实际的都大48
const vector<string> py{"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
if (sum < 10)
{
cout << py[sum];
}
else if ((sum > 10) && (sum < 100))
{
cout << py[sum / 10] << " " << py[sum % 10];
}
else
cout << py[sum / 100] << " " << py[(sum % 100) / 10]<<" "
<< py[sum % 10];
return 0;
}
刷题笔记 PAT1002写出这个数(C++)
最新推荐文章于 2024-05-03 20:05:51 发布