1005. Spell It Right(20)—PAT 甲级
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 甲级的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- PAT 甲级 1005. Spell It Right (20) 【字符串】
题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...
- 【PAT甲级】1005 Spell It Right (20 分)
题意: 给出一个非零整数N(<=10^100),计算每位之和并用英文输出. AAAAAccepted code: #include<bits/stdc++.h> using name ...
- Day 006:PAT练习--1005 Spell It Right (20 分)
上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...
- PAT (Advanced Level) 1005. Spell It Right (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <alg ...
随机推荐
- Angular1.x 基础总结
官方文档:Guide to AngularJS Documentation w3shools angularjs教程 wiki <AngularJS权威教程> Introd ...
- AutoMapper6扩展
简介 很多时候我们使用AutoMapper的时候,都需要进行一个配置才可以使用Mapper.Map<Source,Target>(entity);.如果不进行配置则会报错. 如果实体过多, ...
- centos 7.2 Apache+mysql+php step by step备忘
1. 如何允许laravel程序执行sudo shell脚本? chmod u+w /etc/sudoers ; echo "apache ALL=(ALL) NOPASSWD:ALL&qu ...
- java笔记--String类对象解析与运用
--如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3877236.html "谢谢-- 1.String中的equals和==的 ...
- linux下pgAdmin4安装
首先到pgAdmin4官方网站下载安装包:https://www.pgadmin.org/download/ 我下载的是3.0; 到文件所在目录执行安装命令: sudo pip install ./p ...
- 深圳云栖大会人工智能专场:探索视频+AI,玩转智能视频应用
摘要: 在人工智能时代,AI技术是如何在各行业和领域真正的发挥应用和商业价值,带来产业变革才是关键.在3月28日深圳云栖大会的人工智能专场中,阿里云视频服务技术专家邹娟将带领大家探索熟悉的视频场景中, ...
- 沉淀再出发:ElasticSearch的中文分词器ik
沉淀再出发:ElasticSearch的中文分词器ik 一.前言 为什么要在elasticsearch中要使用ik这样的中文分词呢,那是因为es提供的分词是英文分词,对于中文的分词就做的非常不好了 ...
- Join的加强版CountDownLatch
CountDownLatch允许一个或多个线程等待其他线程完成操作. 假如有这样一个需求:我们需要解析一个Excel里多个sheet的数据,此时可以考虑使用多线程,每个线程解析一个sheet里的数据, ...
- lisp base
一 .quote lisp 使用s-expr表示数据和代码,通常会将第一项作为函数,而将后续元素当做参数传给第一项进行计算.可以通过quote来进行其他解析,quote可用(‘)表示: ( + 1 1 ...
- BZOJ 1041 圆上的整点 数学
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1041 题目大意:求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整 ...