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
/****************************侯尼玛****************************/
一道很简单的题目,没啥思路,记得数字是0的时候得输出zero就行。
附上代码:
#include <iostream> #include <string> using namespace std; string EnglishNum[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; bool FirstWord = true; void SpellTheSum(long long int DigitSum) { if(DigitSum!=0) { SpellTheSum(DigitSum/10); if(!FirstWord) cout<<' '; cout<<EnglishNum[DigitSum%10]; FirstWord=false; } } int main() { long long int DigitSum=0; string Num; while(cin>>Num) { for(size_t i=0;i<Num.size();i++) { DigitSum+=(Num[i]-'0'); } if(DigitSum==0) cout<<"zero"; else SpellTheSum(DigitSum); } return 0; }