码迷,mamicode.com
首页 > 其他好文 > 详细

1005. Spell It Right (20)

时间:2018-01-21 00:00:55      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:顺序   eve   bre   lin   sprint   tween   names   也有   char*   

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)

标签:顺序   eve   bre   lin   sprint   tween   names   也有   char*   

原文地址:https://www.cnblogs.com/yuzhiboprogram/p/8322211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!