A1005. 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 (<= 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
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 char data[10][10] = {"zero", "one", "two", "three","four", "five", "six", "seven", "eight", "nine"}; 5 int main(){ 6 char num[102]; 7 int sum = 0, list[20]; 8 scanf("%s", num); 9 for(int i = 0; num[i] != '\0'; i++) 10 sum += (num[i] - '0'); 11 int a, i = 0; 12 do{ 13 a = sum % 10; 14 sum = sum / 10; 15 list[i++] = a; 16 }while(sum != 0); 17 i--; 18 printf("%s", data[list[i--]]); 19 while(i >= 0){ 20 printf(" %s", data[list[i]]); 21 i--; 22 } 23 cin >> a; 24 return 0; 25 }