1005. Spell It Right (20)
Given a non-negative integer n, your task is to compute the sum of the digits of N, and output every digit of the sum In 中文版.
Input Specification:
Each input file contains the one test case. Each case occupies one line which contains an N (<= 10100).
Output Specification:
For all test case, output in one line the digits of the sum in 中文版 words. There must be one space between-consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
One five
#include <iostream>#include<vector>#include<map>#include<string>using namespacestd;stringSpellintDigit) { if(digit==0) return "Zero"; Else if(digit==1) return " One"; Else if(digit==2) return " Both"; Else if(digit==3) return "three"; Else if(digit==4) return " Four"; Else if(digit==5) return "Five"; Else if(digit==6) return "Six"; Else if(digit==7) return "Seven"; Else if(digit==8) return "Eight"; Else if(digit==9) return "Nine";}intMain () {stringnum; intsum=0; stringRes; CIN>>num; for(intI=0; I<num.size (); i++) Sum+ = (num[i]-'0'); intdigit = sum%Ten; Sum/=Ten; Res= Spell (digit) +Res; while(sum!=0) {digit= sum%Ten; Sum/=Ten; Res= Spell (digit) +" "+Res; } cout<<Res;}
PAT 1005. Spell It Right (20)