题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336
题目大意:给出一个非负整数N,要求你计算出数N的所有位的和,并将其和的每位数用英文对应输出。
思路:N最大在10的100次方,大数。手工写一个大数的加法,再按位输出。
#include<bits/stdc++.h>
using namespace std;
string str;
int t,sum,a[110],idx,top,_max,x;
map<int,string> mp;
int main() {
mp[0]="zero",mp[1]="one",mp[2]="two",mp[3]="three",mp[4]="four",mp[5]="five",
mp[6]="six",mp[7]="seven",mp[8]="eight",mp[9]="nine";
cin>>str;
idx=0;
for(int i=0; i<str.length(); i++) {
x=str[i]-'0';
a[idx]=a[idx]+x;
if(a[idx]>=10) {
a[idx]=a[idx]-10;
top=idx+1;
while(1) {
if(a[top]+1<10) {
a[top]++;
break;
} else {
a[top]=a[top]+1-10;
top++;
}
}
_max=max(_max,top);
}
}
for(int i=_max; i>=0; i--) {
if(i==_max) cout<<mp[a[i]];
else cout<<' '<<mp[a[i]];
}
}