https://pintia.cn/problem-sets/994805260223102976/problems/994805324509200384
pat乙级第二题处理过大的整数会发生溢出,此时可以采用string或者数组来储存
#include<iostream>
#include<cstring>
#include"map"
using namespace std;
int f(string n)
{
if(n.length()==1)
return n[0]-'0';
else
return (n[0]-'0')+f(n.substr(1));
}
void ff( int x,map<int,string> &a)
{
if(x<10)
{
cout<<a[x];
return;
}
else
{
ff(x/10,a);
cout<<' '<<a[x%10];
}
}
int main()
{
map<int,string> a;
a[0]="ling";
a[1]="yi";
a[2]="er";
a[3]="san";
a[4]="si";
a[5]="wu";
a[6]="liu";
a[7]="qi";
a[8]="ba";
a[9]="jiu";
string n;
cin>>n;
ff(f(n),a);
return 0;