1005 Spell It Right (20)(20 point(s))
problem
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 (<= 10^100^).
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
tip
求位数上数字的和。
anwser
using namespace std;
string GetName(int i){
switch(i){
case 0: return "zero";
case 1: return "one";
case 2: return "two";
case 3: return "three";
case 4: return "four";
case 5: return "five";
case 6: return "six";
case 7: return "seven";
case 8: return "eight";
case 9: return "nine";
}
}
int main(){
// freopen("test.txt", "r", stdin);
string N;
int sum = 0;
cin>>N;
for(int i = 0; i < N.size(); i++){
sum += (int)N[i]-48;
}
if (sum == 0) {
cout<<GetName(sum);
return 0;
}
// cout<<sum;
vector<int> di;
while(sum > 0){
di.push_back(sum%10);
sum/=10;
}
reverse (di.begin(), di.end());
for(size_t i = 0; i < di.size(); i++){
if (i == 0) cout<<GetName(di[i]);
else cout<<" " << GetName(di[i]);
}
return 0;
}
experience
边界条件:
- 非负数 有0的情况。
时间就是生命,应该是10分钟解决的,却花了 20分钟。
1005 Spell It Right (20)(20 point(s))的更多相关文章
- PTA 1005 Spell It Right (20)(20 分)水题
1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...
- A1035 Password (20)(20 分)
A1035 Password (20)(20 分) To prepare for PAT, the judge sometimes has to generate random passwords f ...
- PAT 甲级 1011 World Cup Betting (20)(20 分)
1011 World Cup Betting (20)(20 分)提问 With the 2010 FIFA World Cup running, football fans the world ov ...
- PAT 甲级 1001 A+B Format (20)(20 分)
1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...
- PAT 1049 数列的片段和(20)(代码+思路分析)
1049 数列的片段和(20)(20 分) 给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段.例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2 ...
- PAT 1033 旧键盘打字(20)(20 分)
1033 旧键盘打字(20)(20 分) 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在2 ...
- 【PAT】1019 数字黑洞 (20)(20 分)
1019 数字黑洞 (20)(20 分) 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字.一直重复这样做, ...
- PAT 1054 求平均值 (20)(代码+思路+测试用例)
1054 求平均值 (20)(20 分) 本题的基本要求非常简单:给定N个实数,计算它们的平均值.但复杂的是有些输入数据可能是非法的.一个"合法"的输入是[-1000,1000]区 ...
- 【PAT】1018 锤子剪刀布 (20)(20 分)
1018 锤子剪刀布 (20)(20 分) 大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算 ...
- PAT 甲级 1011 World Cup Betting (20)(20 分)(水题,不用特别在乎精度)
1011 World Cup Betting (20)(20 分) With the 2010 FIFA World Cup running, football fans the world over ...
随机推荐
- HDU 2722 Here We Go(relians) Again (最短路)
题目链接 Problem Description The Gorelians are a warlike race that travel the universe conquering new wo ...
- js鼠标自定移入输入框文本框光标自动定位到文本框
1.干货直接上 选中输入框设置如下: document.getElementById("Text1").focus();
- Oracle新建数据库,并导入dmp文件
1:安装Oracle及新建数据库 Oracle 11g安装图解 http://www.cnblogs.com/qianyaoyuan/archive/2013/05/05/3060471.html h ...
- 关于禁用"请停用以开发者模式运行的扩展程序"提示
有兴趣研究谷歌浏览器扩展开发,但每次开启高版本chrome都会有烦人的提示 因为我用的360急速,目前还有提示,但使用原生chrome连插件都给删了,无语
- JavaScript 实用技巧和写法建议
1.前言 从大学到现在,接触前端已经有几年了,感想方面,就是对于程序员而言,想要提高自己的技术水平和编写易于阅读和维护的代码,我觉得不能每天都是平庸的写代码,更要去推敲,去摸索和优化代码,总结当中的技 ...
- Oracle03--子查询
1. 子查询 子查询也称之为嵌套子句查询. 1.1. 语法 语法上的运行使用规则: l 子查询 (内查询.嵌套子句) 在主查询之前一次执行完成.(子查询先执行) l 子查询的结果被主查询使用 (外查询 ...
- 【codeforces】【比赛题解】#869 CF Round #439 (Div.2)
良心赛,虽然我迟了半小时233333. 比赛链接:#869. 呃,CF的比赛都是有背景的……上次是<哈利波特>,这次是<物语>…… [A]巧妙的替换 题意: Karen发现了石 ...
- python几种装饰器的用法
用函数装饰函数 这种比较常见首先定义装饰器函数 def cache(func): data = {} @wraps(func) def wrapper(*args, **kwargs): key = ...
- 002_安装第三方APP好的站点及解除安全与隐私限制
一.解除安全与隐私限制的任何来源. http://bbs.feng.com/read-htm-tid-10714286.html 接下来,我们就打开终端,然后输入以下命令: sudo spctl ...
- 【前端开发】localStorage的用法
localStorage.setItem("name","value") //存储name的值 var type = localStorage.getItem ...