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. ASP.NET MVC学习笔记 第二天

    创建视图      返回给客户端的HTML代码最好通过视图指定.视图都在Views文件夹中定义.ViewsDemo控制器的视图需要一个ViewsDemo子目录,这是视图的约定.      可以把多个控 ...

  2. 应用程序和Activity

    Android 应用程序的组成部分 Android应用程序由各个组件组成,并使用Manifest绑定到一起,Manifest描述了每一个组件和它们之间的交互方式,还用于指定权限,硬件,平台以及应用程序 ...

  3. JavaScript运算符优先级引起的bug

    [下面是昨天发给同事的邮件,为防止泄露商业机密,隐去了项目名和变量名] ==================================================== 昨天发现Nx代码中的一 ...

  4. day04之VUE痛悟

    vue组件组件分为三部分

  5. 个人总结-7- 实现图片在MySQL数据库中的存储,取出以及显示在jsp页面上

    昨天主要是进行对数据库的内容提取出来并进行动态显示,这个只需要设置一个servlet从数据库中获取数据即可,只是图片比较特殊,不能显示. 今天准备继续找方法来实现图片得录入和显示到jsp中,准备从网上 ...

  6. 数据迁移:MSSQL脚本文件过大,客户端没有足够的内存继续执行程序

    在CMD窗口(俗称:黑屏程序) 下输入 SQLCMD 命令 命令格式如下: sqlcmd -U 用户名   -P 密码    -S 服务器地址   -d 数据库名称  -i  你的脚本文件.sql ( ...

  7. String str = "1,2,3,4,5,6" 如何将这个字符串转换成int数组

    String str = "1,2,3,4,5,6"; string[] strS = str.Split(','); int[] num = new int[strS.Lengt ...

  8. VS :不会命中断点 代码版本与原始版本不同

    设置了断点,但是无法中断,提示"不会命中断点 代码版本与原始版本不同".这种情况下一般是生成的bin\debug下面的文件与实际代码不符. 但是这次确实没有问题,重新更新程序,清理 ...

  9. Java学习---Excel读写操作

    1.1.1. 简介 Apache POI 使用Apache POI 完成Excel读写操作 Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API ...

  10. 用setTimeout实现动态时钟的效果

    1.获取到系统时间 2.获取到当地时间字符串 3.开启延时器,每一秒刷新一次时间 <!DOCTYPE html> <html> <head> <meta ch ...