1005. Spell It Right (20)

Posted yuzhiboprogram

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1005. Spell It Right (20)相关的知识,希望对你有一定的参考价值。

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

/*输入小于=100位数的string
把他们全部加起来,然后和,顺序输出*/
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int charint(char a)
{
  int b = a - ‘0‘;
  return b;
}
char* gc(char a)//其实那个break是没用的吧,
{
  switch (a)
{
case ‘1‘:
  return "one"; break;
case ‘0‘:
  return "zero"; break;
case ‘2‘:
  return "two"; break;
case ‘3‘:
  return "three"; break;
case ‘4‘:
  return "four"; break;
case ‘5‘:
  return "five"; break;
case ‘6‘:
    return "six"; break;
case ‘7‘:
  return "seven"; break;
case ‘8‘:
  return "eight"; break;
case ‘9‘:
  return "nine"; break;
}
}
int main()
{
   string s;
  cin >> s;
  int sum = 0;
for (int i = 0; i < s.size(); i++)
{
sum += charint(s[i]);
}//可能存在,输入为空的情况,事实证明,测试用例里面,不存在这个情况
char b[100];
int len = sprintf(b,"%d",sum);//这个函数帮我节约了不少时间。应该是我感觉轻松的最主要的一个原因 。
printf("%s",gc(b[0]));//返回值是char*类型,指向字符串的首地址
for (int i = 1;i < len; i++)
{
printf(" %s",gc(b[i]));
}
return 0;
}

 

不是说,甲级的第一题的难度约等于乙级的最后一题嘛,我怎么感觉甲级的第一题,有点简单。也有可能是我工作的一个月时间里面进步了?

 

以上是关于1005. Spell It Right (20)的主要内容,如果未能解决你的问题,请参考以下文章

1005. Spell It Right (20)

1005. Spell It Right (20)

1005. Spell It Right (20)

1005. Spell It Right (20)

1005. Spell It Right (20)(模拟题)

1005. Spell It Right(20)—PAT 甲级