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
题意:给出一个数字,计算每一位的和,然后逐位输出位数上的数字
解析:以字符串形式输入,然后求和。把这个和转换成字符串,再逐位输出。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
using namespace std;
string digits [] = { "zero","one","two","three","four","five","six","seven","eight","nine"};
int main()
{
char name[1005];
cin>>name;
int len = strlen(name);
int sum = 0;
for(int i = 0; i < len; i ++)//求和
{
sum += (name[i]-'0');
}
int a[1006] = {0};
int counts = 0;
if(!sum)//为0的情况
{
printf("zero");
return 0;
}
while(sum)
{
a[counts] = sum%10;
sum = sum/10;
counts ++;
}
for(int i = counts - 1; i > 0; i --)
{
cout<<digits[a[i]]<<" ";
}
cout<<digits[a[0]];
}