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
翻译:
给定一个非负整数 N,您的任务是计算 N 的所有数字的总和,并用英语输出总和的每个数字。
输入规范:
每个输入文件包含一个测试用例。每个案例占用一行,其中包含 N (≤10
100
).
输出规格:
对于每个测试用例,在一行中输出英文单词的总和数字。两个连续单词之间必须有一个空格,但行尾不能有多余的空格。
#include<iostream>
#include<cstring>
using namespace std;
const int N = 1000;
char in[N];
string answer[] ={"zero","one","two","three","four","five",
"six","seven","eight","nine"};
long long sum;
int main()
{
cin >>in;
int n = strlen(in);
for(int i = 0; i < n; i++)
sum += in[i]-'0';
//cout<<sum<<"\n";
string p = to_string(sum);
int pn = p.length();
for(int i = 0; i < pn-1; i++)
{
int num = p[i]-'0';
cout<<answer[num]<<" ";
}
int num =p[pn-1]-'0';
//cout<<" num"<<num;
cout<<answer[num];
cout<<"\n";
return 0;
}