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. 线性表的Java实现--链式存储(单向链表)

    单向链表(单链表)是链表的一种,其特点是链表的链接方向是单向的,对链表的访问要通过顺序读取从头部开始. 链式存储结构的线性表将采用一组任意的存储单元存放线性表中的数据元素.由于不需要按顺序存储,链表在 ...

  2. 基于PMBOK的项目管理知识体系

  3. Python 生成器总结

    生成器的概念: 生成器不会把结果保存在一个系列中,而是保存在生成器的状态,在每次进行迭代时返回一个值,直到遇到StopIteration异常结束 生成器是这样一个函数,它记住上一次返回时在函数体中的位 ...

  4. Python学习---django重点之视图函数

    django重点之视图函数 http请求中产生两个核心对象: http请求:HttpRequest对象,由Django自己创建 http响应:HttpResponse对象,由开发自己创建,必须返回一个 ...

  5. docker容器修改hosts文件,重启失效问题解决

    docker容器修改hosts文件 搜了一大批资料,有说需要在docker run --hosts...改:dockerfile改:有点麻烦,下面方案比较好: 参照docker吧(https://ti ...

  6. 初进MFC的世界,太奇妙。第六次作业----未完待续

    又一次的迁徙.我希望能够早些抵达. 第六次作业-未完待续!图形界面,计算器文件 本次的作业是给自己的计算器加一个可视化的窗口,我开始也是很激动和憧憬的,看了很多的界面库,发现并没有想象的那么简单,因为 ...

  7. list 去重并保持原来排序

    public <T> List<T> removeDuplicateKeepOrder(List<T> list){ /* Set set = new HashSe ...

  8. h5标签

    1.<abbr> 标签指示简称或缩写,比如 "WWW" 或 "NATO". IE 6 或更早版本的 IE 浏览器不支持 <abbr> 标 ...

  9. ubuntu命令安装jdk

    1.ubuntu使用的是openjdk,所以我们需要先找到合适的jdk版本.在命令行中输入命令: $apt-cache search openjdk 1 返回结果列表(因个人电脑而有所不同): def ...

  10. 死磕salt系列-salt 常用modules

    saltstack 常用模块介绍 file模块 被控主机文件常见操作,包括文件读写.权限.查找.校验等 salt '*' file.get_sum /etc/resolv.conf md5 salt ...