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 ...
随机推荐
- 渗透测试===使用BURPSUIT暴力破解某网站的手机验证码
手机短信验证是企业给消费者(用户)的一个凭证,通过手机短信内容的验证码来验证身份.主要用来用户注册,找回密码,用户登录等等作为强身份认证. 目前验证码的格式主要是数字,从4位到6位不等.一般来说验 ...
- django Rest Framework----认证/访问权限控制/访问频率限制 执行流程 Authentication/Permissions/Throttling 源码分析
url: url(r'books/$',views.BookView.as_view({'get':'list','post':'create'})) 为例 当django启动的时候,会调用执行vie ...
- Oracle JDeveloper 10g 卡顿、花屏的解决方法
1.JDeveloper 10g花屏的解决办法: 在Win7或WinXP环境下,JDeveloper10g可能产生花屏现象,给开发者造成困扰,解决方法如下: 打开{JDEV_HOME}\jdev\bi ...
- Luogu P1535 【游荡的奶牛】
搜索不知道为什么没有人写bfs觉得挺像是标准个bfs的 状态因为要统计次数,不能简单地跳过一个被经过的点这样的话,状态量会爆炸采用记忆化设dp[i][j][k]表示在第k分钟到达点(i,j)的方案数以 ...
- ZK分布式锁(未完 待续)
实现思路 公平锁:创建有序节点,判断本节点是不是序号最小的节点(第一个节点),若是,则获取锁:若不是,则监听比该节点小的那个节点的删除事件. 非公平锁:直接尝试在指定path下创建节点,创建成功,则说 ...
- sqlserver字符串合并(merge)方法汇总
--方法1--使用游标法进行字符串合并处理的示例.--处理的数据CREATE TABLE tb(col1 varchar(10),col2 int)INSERT tb SELECT 'a',1UNIO ...
- 20155225 2006-2007-2 《Java程序设计》第3周学习总结
20155225 2006-2007-2 <Java程序设计>第3周学习总结 教材学习内容总结 封装对象内部数据:使用private关键字定义类的私有成员 如果不使用private定义的话 ...
- Ninject中如果在抽象类中使用了属性注入,则属性必须设置为protected或public
Ninject中如果在抽象类中使用了属性注入,则属性必须设置为protected或public 不能使用private,否则无法注入成功,会报null异常
- Java学习(异常类练习题)
练习题: 1.计算圆的面积,半径不能为零和负数 package com.oracle.Demo01; public class Demo02 { // 写一个计算圆的面积的方法,传一个半径,返回面积 ...
- nullptr
以前都是用0来表示空指针的,但由于0可以被隐式类型转换为整形,这就会存在一些问题.关键字nullptr是std::nullptr_t类型的值,用来指代空指针.nullptr和任何指针类型以及类成员指针 ...