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:12345Sample Output:
one five
#include <iostream>
#include <string>
#include <stack>
using namespace std;
#define N 101
void Print_Number(int num)
{
switch (num)
{
case 0:
cout<<"zero";
break;
case 1:
cout<<"one";
break;
case 2:
cout<<"two";
break;
case 3:
cout<<"three";
break;
case 4:
cout<<"four";
break;
case 5:
cout<<"five";
break;
case 6:
cout<<"six";
break;
case 7:
cout<<"seven";
break;
case 8:
cout<<"eight";
break;
default:
cout<<"nine";
}
}
int main(int argc, const char * argv[])
{
//Store the number by string
char Str[N]={0};
cin>>Str;
//Caculate the sum of the number
int i=0,sum=0;
int temp=0;
while (Str[i]!='\0')
{
temp=Str[i]-'0'+0;
sum+=temp;
i++;
}
//Output sum by English
stack<int> Q;
int remain=0;
if (sum==0)
{
cout<<"zero";
}else
{
while (sum!=0)
{
Q.push(sum%10);
sum/=10;
}
int flag=0;//标志用来判断第几次输出,第一次输出不输出空格
while (!Q.empty())
{
temp=Q.top();
Q.pop();
if(!flag)
{
Print_Number(temp);
flag=1;
}else
{
cout<<' ';
Print_Number(temp);
}
}
}
return 0;
}