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. .NET 中数据访问用的 DBHelper(Sql Server) 类

    public class DBHelper { private static string DBConnectString = "Data Source=.;Initial Catalog= ...

  2. 《Java基础知识》Java 反射详解

    定义 JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意方法和属性:这种动态获取信息以及动态调用对象方法的功能称为java语言的反射 ...

  3. python基础知识第五篇(字典)

    字典(dict) info={ "k1":"v1", "k2":"value" } 字典的value可以是任意值,布尔值 ...

  4. Fuchsia文章汇总

    今日,windows时代的十年已经过去,android/ios时代的十年也行将结束,下一个十年是谁的十年? 操作系统做为软件的基石,做为基础服务的基础,因为各层应用框架的层层封装,正在变的越来越透明, ...

  5. 【每天一题】LeetCode 0107. 自底向上层遍历二叉树

    开源地址:点击该链接 题目描述 * 给定一个二叉树,返回其节点值自底向上的层次遍历. * 即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历 * * 例如: * 给定二叉树 [3,9,20,nul ...

  6. python多线程编程-queue模块和生产者-消费者问题

    摘录python核心编程 本例中演示生产者-消费者模型:商品或服务的生产者生产商品,然后将其放到类似队列的数据结构中.生产商品中的时间是不确定的,同样消费者消费商品的时间也是不确定的. 使用queue ...

  7. C# 控制台输入和输出

    目录 从控制台获取输入 将输出写入控制台 Console.Write() Console.WriteLine() 格式字符串 多重标记和值 格式化字符串 索引 对齐说明符 格式字段 标准数字格式说明符 ...

  8. JS---part5 课程介绍 & part4 复习

    part5 课程介绍 另一个定时器 第一个定时器的小案例----练习 封装动画函数----------匀速的动画函数,过渡到=======>缓动的动画函数 简单的轮播图 左右焦点的轮播图 无缝连 ...

  9. Java_垃圾回收算法

    参考:<深入理解JAVA虚拟机>第二版 3.3 垃圾收集算法 由于垃圾收集算法的实现涉及大量的程序细节,而且各个平台的虚拟机操作内存的方法又各不相同,只是介绍几种算法的思想及其发展过程. ...

  10. linux中批量添加文件前缀的操作

    需要在文件夹内所有txt文件的文件名前面添加"gt_"; 就是由原来的文件“xxx.txt”变成“gt_xxx.txt”: 网上搜来的脚本如下: for i in `ls`; do ...