题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Input Specification:
Each input file contains one test case. Each case occupies one line which contains an N (≤10100).
Output Specification:
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
one five
non-negative 非负的 consecutive 连续的
:题意 将n中的各个位的数字相加求和,并以英文字符形式输出和的每一位。
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int ans=0;
char str[111];
char s[111];
cin>>str;
for(int i=0;i<strlen(str);i++){
ans+=(str[i]-'0');
}
sprintf(s,"%d",ans);
string a[11]={"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
//或者char a[10][15]={...}
cout<<a[s[0]-'0'];
for(int i=1;i<strlen(s);i++){
cout<<" "<<a[s[i]-'0'];
}
return 0;
}