首页 > 其他 > 详细

1005. Spell It Right (20)

时间:2015-12-06 11:11:35      阅读:212      评论:0      收藏:0      [点我收藏+]

注意字符串的输入方法

  1. char a[100] = { 0 };
  2. scanf("%s", &a);

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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. #pragma warning(disable:4996)
  2. /**/
  3. #include <stdio.h>
  4. #include <string.h>
  5. using namespace std;
  6. void PrintNum(int a);
  7. int main(void){
  8. char a[100] = { 0 };
  9. int sum = 0,b=0;
  10. scanf("%s", &a);
  11. for (int i = 0; i < 100; i++){
  12. if (a[i]!=0)
  13. sum += (a[i] - ‘0‘);
  14. }
  15. if (sum >= 100){
  16. b = sum / 100;
  17. PrintNum(b);
  18. printf(" ");
  19. b = sum / 10 % 10;
  20. PrintNum(b);
  21. printf(" ");
  22. b = sum % 10;
  23. PrintNum(b);
  24. }
  25. else if (sum > 10){
  26. b = sum / 10;
  27. PrintNum(b);
  28. printf(" ");
  29. b = sum % 10;
  30. PrintNum(b);
  31. }
  32. else{
  33. PrintNum(sum);
  34. }
  35. return 0;
  36. }
  37. void PrintNum(int a){
  38. if (a == 0){
  39. printf("zero");
  40. }
  41. else if (a == 1)
  42. printf("one");
  43. else if (a == 2)
  44. printf("two");
  45. else if (a == 3)
  46. printf("three");
  47. else if (a == 4)
  48. printf("four");
  49. else if (a == 5)
  50. printf("five");
  51. else if (a == 6)
  52. printf("six");
  53. else if (a == 7)
  54. printf("seven");
  55. else if (a == 8)
  56. printf("eight");
  57. else if (a == 9)
  58. printf("nine");
  59. else;
  60. }





1005. Spell It Right (20)

原文:http://www.cnblogs.com/zzandliz/p/5023033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!