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<stdio.h> #include<string.h> char number[100]; int reminder[10]; int main(){ scanf("%s", &number); int i; int sum = 0; for (i=0;i<strlen(number);i++) sum += number[i] - '0'; // printf("sum = %d\n", sum); if(sum == 0){ printf("zero\n"); } else { for(i=0; i < 10 && sum !=0; i++){ reminder[i] = sum%10; sum /= 10; // printf("reminder[%d] = %d\n", i, reminder[i]); } for(i = i -1; i >=0; i--){ print(reminder[i]); if(i != 0) printf(" "); else printf("\n"); } } return 0; } void print(int number){ switch(number){ case 0: printf("zero"); break; case 1: printf("one"); break; case 2: printf("two"); break; case 3: printf("three"); break; case 4: printf("four"); break; case 5: printf("five"); break; case 6: printf("six"); break; case 7: printf("seven"); break; case 8: printf("eight"); break; case 9: printf("nine"); break; } }
NOTES:
1.string -- scanf("%s", &number);
2.sum += number[i] - '0';
3.注意边界case
4.string length -- #include<string.h> strlen(number);
5.http://beej.us/guide/bgc/output/html/multipage/scanf.html
scanf
h
The value to be parsed is a short int or short unsigned. Example: %hd or %hu.
l
The value to be parsed is a long int or long unsigned, or double (for %f conversions.) Example: %ld, %lu, or %lf.
L
The value to be parsed is a long long for integer types or long double for float types. Example: %Ld, %Lu, or %Lf.
*
6.max int: 2147483647
max long long 9223372036854775807