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
 
题目意思:对所给的一个非负整数n,求各位之和的每一位英文读音。
解题思路:先求所给n的各位之和sum,转换成string,输出对应的每一位读音即可。
 
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int i,sum=;
string str;
string ans;
string a[]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
cin>>str;
for(i=; i<str.size(); i++)
{
sum+=str[i]-'';
}
ans=to_string(sum);
cout<<a[ans[]-''];//第一个读音
for(i=;i<ans.size();i++)
{
cout<<" "<<a[ans[i]-''];
}
return ;
}

PAT 1005 Spell It Right 字符串处理的更多相关文章

  1. PAT 1005 Spell It Right

    1005 Spell It Right (20 分)   Given a non-negative integer N, your task is to compute the sum of all ...

  2. PAT甲1005 Spell it right【字符串】

    1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...

  3. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...

  4. PAT 甲级 1005 Spell It Right (20)(代码)

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...

  5. PAT 甲级 1005 Spell It Right (20 分)

    1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...

  6. PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏

    1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  7. PAT 1005

    1005. Spell It Right (20) Given a non-negative integer N, your task is to compute the sum of all the ...

  8. 1005 Spell It Right (20 分)

    1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...

  9. 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 ...

随机推荐

  1. Ubuntu系统下arm-linux-gcc交叉编译环境搭建过程

    搭建所需环境Linux版本:Ubuntu 14.10 交叉编译器版本:arm-linux-gcc-4.4.3资源链接 何为交叉编译环境搭建交叉编译环境,即安装.配置交叉编译工具链.在Ubuntu环境下 ...

  2. 安卓逆向基础(001)-APK安装流程

    1.在/data/app下以报名为文件夹名新建文件夹 APK包存放在这里 以及lib文件 存放so 2./data/dalvik-cache 存放dex dex是dalvik虚拟机可执行文件 3./d ...

  3. Instrument API介绍

    1. Instrumentation介绍  JVMTI(JVM Tool Interface)是 Java 虚拟机所提供的 native 编程接口,是 JVMPI(Java Virtual Machi ...

  4. python基础知识第九篇(函数)

    函数 >>>>>>>>>>> : 使用函数的好处 1.代码重用 2.保持一致性,方便维护 3.可扩展性 定义方法 def test01 ...

  5. Internet History,Technology,and Security -Technology: Application Protocols(Week7)

    Week7 Technology: Application Protocols This week, we’ll be covering application protocols. With rel ...

  6. python子类如何继承父类的实例变量?

    类型1:父类和子类的实例变量均不需要传递 class A(object): def __init__(self): self.name = "cui" def get_name(s ...

  7. Fragment中不能使用自定义带参构造函数

    通过Fragment自定义的静态方法将值从activity传到fragment中,然后就想到这样不是多次一举吗,为什么不直接写个带参构造函数将值传过去呢?试了一下,发现Fragment有参构造函数竟然 ...

  8. iOS核心动画高级技巧-5

    9. 图层时间 图层时间 时间和空间最大的区别在于,时间不能被复用 -- 弗斯特梅里克 在上面两章中,我们探讨了可以用CAAnimation和它的子类实现的多种图层动画.动画的发生是需要持续一段时间的 ...

  9. WSL2(预览版)体验笔记

    WSL2安装 WSL2在今年5月份Microsoft Build大会上发布了,但至今Windows10一直没收到更新推送,我想这么久过去就算没进入正式,至少也到了RC版了吧,于是开始折腾准备体验一把. ...

  10. JPA中实现单向多对一的关联关系

    场景 JPA入门简介与搭建HelloWorld(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103473937 ...