1005 Spell It Right
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 (≤ 1 0 100 10^{100} 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
#include<cstdio>
#include<cstring>
int main()
{
char digit[10][6] = { "zero","one","two","three","four","five","six","seven","eight","nine" };
char N[110]={0};
scanf_s("%s", &N,sizeof(char)*110);
int re = 0;
int len_N = strlen(N);
for (int i = 0; i < len_N; i++)
{
re += N[i]-'0';
}
if (re == 0)
printf("zero");
int len = 0;
int digits[5] = { 0 };
while (re)
{
digits[len] = re % 10;
re = re / 10;
len++;
}
for (len--; len >= 0; len--)
{
printf("%s", digit[digits[len]]);
if (len > 0)
{
printf(" ");
}
}
}
本题要点在于,初始值N的范围为不大于 1 0 100 10^{100} 10100,远超long long型数据的范围,所以在写入时需要用字符串类型