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的位数高达100位,所以用字符串输入并遍历字符串得到所有数字的和,利用c++自带的to_string函数将和转化为整数类型,最后利用常量数组进行输出转换。

#include <iostream>
#include <string>
using namespace std;
const string num[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main() {
string str;
int sum=0;
cin>>str;
for(auto c:str) {
sum+=c-'0';
}
string s=to_string(sum);
for(auto c:s) {
if(c!=s.front()) cout<<" ";
cout<<num[c-'0'];
}
cout<<endl;
return 0;
}

1005. Spell It Right(20)—PAT 甲级的更多相关文章

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

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

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

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

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

  6. PAT 甲级 1005. Spell It Right (20) 【字符串】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...

  7. 【PAT甲级】1005 Spell It Right (20 分)

    题意: 给出一个非零整数N(<=10^100),计算每位之和并用英文输出. AAAAAccepted code: #include<bits/stdc++.h> using name ...

  8. Day 006:PAT练习--1005 Spell It Right (20 分)

    上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...

  9. PAT (Advanced Level) 1005. Spell It Right (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  10. PAT甲题题解-1005. Spell It Right (20)-数位求和,水

    把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <alg ...

随机推荐

  1. 计算球面两点间距离实现Vincenty+Haversine

    vincenty公式  精度很高能达到0.5毫米,但是很慢. Haversine公式半正矢公式,比vincenty快,精度没有vincenty高,也长使用. --------------------- ...

  2. Android N(API level 24.)废弃了Html.fromHtml(String)

    从API level 24开始,fromHtml(String)被废弃,使用fromHtml(String source, int flags) 代替 flags: FROM_HTML_MODE_CO ...

  3. Java 设计模式(三)-单例模式(Singleton Pattern)

    1     概念定义 1.1   定义 确保一个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 1.2   类型 创建类模式 1.3   难点 1)多个虚拟机 当系统中的单例类被拷贝运行在多 ...

  4. Python套接字

    1.客户端/服务器架构 什么是客户端/服务器架构?对于不同的人来说,它意味着不同的东西,这取决于你问谁以及描述的是软件还是硬件系统.在这两种情况中的任何一种下,前提都很简单:服务器就是一系列硬件或软件 ...

  5. CentOS7路由、端口和服务排障常用命令

    1. ip route   显示主机基本路由信息 ~]# ip route default via 172.25.0.254 dev eth0  proto static  metric 1024 1 ...

  6. 【最强】微软Tech Summit 2017动手实验室教程

    [最强]微软Tech Summit 2017动手实验室教程 原创 2017-11-07 MSPrecious MSPrecious成长荟 这是! 你绝对找不到的教程! Ignite2016的教程你找到 ...

  7. XML序列化 System.Xml.Serialization

    一.定义元数据 XML序列化常用属性:XMLRoot,XMlType.XMLText.XMLEnum等 [Serializable] [XmlRoot] public class Product { ...

  8. Linux系统之路——如何在服务器用U盘安装CentOS7.2(一)

    终于将CentOS7装上服务器(thinkserver250,不得不说联想的太烂了)了,过程无比艰辛,因为我发现网上大家提到的所有U盘安装CentOS7时碰到的问题几乎都被我碰到了,像什么: 1.刻录 ...

  9. centos虚拟机安装,配置静态ip可以访问网络

    centos安装过程中需要注意几个问题 1.选择安装的软件 默认选择的是mininal,应该选择GNEME Desktop 安装的过程中可以设置network 配置linux网络命令 具体配置 退出键 ...

  10. angularJs中的模块化操作

    一.全局的写法 有可能会跟其他程序有冲突 <!DOCTYPE HTML> <html ng-app="myApp"> <head> <me ...