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 ...
随机推荐
- 【javascript】javascript设计模式mixin模式
概述: Mixin是JavaScript中用的最普遍的模式,几乎所有流行类库都会有Mixin的实现.任意一个对象的全部或部分属性拷贝到另一个对象上. 一 .混合对象 二 .混合类
- Linux基础入门之网络属性配置
Linux基础入门之网络属性配置 摘要 Linux网络属性配置,最根本的就是ip和子网掩码(netmask),子网掩码是用来让本地主机来判断通信目标是否是本地网络内主机的,从而采取不同的通信机制. L ...
- VS2013下使用log4cplus
原文:http://blog.csdn.net/qq_35850668/article/details/52522932 最近工作需要,需要使用log库来完善日志类记录,由于之前没什么经验,遇到了很多 ...
- Java Basis
java中.java源文件放在src文件夹下,.class文件放在bin文件夹下. java代码区域,以及控制台区域字体大小更改.Java->Java Editor Text Font ...
- 131.007 Unsupervised Learning - Feature Selection | 非监督学习 - 特征选择
1 Why? Reason1 Knowledge Discovery (about human beings limitaitons) Reason2 Cause of Dimensionality ...
- 排查在 Azure 中新建 Windows VM 时遇到的部署问题
尝试创建新的 Azure 虚拟机 (VM) 时,遇到的常见错误是预配失败或分配失败. 当由于准备步骤不当,或者在从门户捕获映像期间选择了错误的设置而导致 OS 映像无法加载时,将发生预配失败. 当群集 ...
- 购买 In-app Billing 商品
购买 In-app Billing 商品 一旦你的应用连接上了 Google Play,你就可以初始化内购商品的购买请求了.Google Play 提供了结算接口,可以让用户进入使用他们的支付方式,所 ...
- December 30th 2016 Week 53rd Friday
Life without love is like a tree without blossoms or fruit. 缺少爱的生活就像从未开花结果的枯树. Love is not only the ...
- ZT 设计模式六大原则(1):单一职责原则
zt 设计模式六大原则(1):单一职责原则 分类: 设计模式 2012-02-21 09:52 25059人阅读 评论(65) 收藏 举报 设计模式stringclass编程 (THERE SHOUL ...
- npm WARN network …… request to https://cnpmjs.…… failed, reason: socket hang up
出现类似问题的原因是由于之前配置了镜像导致的 解决方案:删掉镜像,使用npm本身进行安装 删除镜像的命令: 方法1: npm config delete registry 方法2: npm confi ...