上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点!

显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们可以使用字符串输入,之后分别遍历每一位,将其分别存入sum中。

因为是从高到低输出每一位,而不是从低到高:若是后者,则可以使用一个小函数不断取余再除以10即可全部输出;此时是前者,则可使用sstream头文件,将sum转换为字符串形式,再分别遍历每一位,输出每一位的值对应的字符数组分量,即可AC。

这里我们要注意,要不就使用字符串数组存储数字转换出的英文单词;否则若使用普通的字符数组的话,要在变量名前加※,以表示其为一个分量不限长度的字符数组,输出时也要以字符串形式输出

代码如下:

#include<iostream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
using namespace std;
char *num[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
void ans(string s){
for(int i = 0; i < s.length(); i++){
printf("%s", *(num + int(s[i] - 48)));
if(i != s.length() - 1){
printf(" ");
}
}
}
int main(){
string s;
getline(cin, s);
int len = s.length(), sum = 0;
for(int i = 0; i < len; i++){
sum += (s[i] - 48);
}
stringstream ss;
string temp;
ss << sum;
ss >> temp;
ans(temp);
return 0;
}

继续加油!争取能拿90+!

Day 006:PAT练习--1005 Spell It Right (20 分)的更多相关文章

  1. PAT Advanced 1005 Spell It Right (20 分)

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

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

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

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

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

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

  7. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) (switch)

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

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

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

  9. 1005 Spell It Right (20 分)

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

随机推荐

  1. CF1479X Codeforces Round #700

    C Continuous City(图的构造) 题目大意:让你构造一个n\le 32的有向无环无重边图,使得从1走到n的所有路径长度在L,R之间,且每种长度的路径只有唯一一条,$L,R\le 1e6$ ...

  2. SpringAOP--代理

    前言 在Spring或者SpringBoot中,可以通过@Aspect注解和切点表达式等配置切面,实现对某一功能的织入.然而其内部到底是如何实现的呢? 实际上,Spring在启动时为切点方法所在类生成 ...

  3. 两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对?

    对. 因为equals()方法可以用开发者重写,hashCode()方法也可以由开发者来重写,因此它们是否相等并没有必然的关系. 如果对象要保存在HashSet或HashMap中,它们的equals( ...

  4. kafka 为什么那么快?

    Cache Filesystem Cache PageCache缓存 顺序写 由于现代的操作系统提供了预读和写技术,磁盘的顺序写大多数情况下比随机写内存还要快. Zero-copy 零拷⻉技术减少拷贝 ...

  5. spring-boot-learning-Web开发知识

    1).创建SpringBoot应用,选中我们需要的模块: 2).SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置就可以运行起来 3).自己编写业务代码: 文件名的功能 x ...

  6. 什么是 Spring 引导的执行器?

    Spring Boot 执行程序提供了 restful Web 服务,以访问生产环境中运行应用程序 的当前状态.在执行器的帮助下,您可以检查各种指标并监控您的应用程序.

  7. 解释AOP模块?

    AOP模块用于发给我们的Spring应用做面向切面的开发, 很多支持由AOP联盟提供,这样就确保了Spring和其他AOP框架的共通性.这个模块将元数据编程引入Spring.

  8. 构造器constructor是否可被重写override?

    构造器不能被继承,因此不能被重写,但可以被重载.

  9. 学习Nginx(一)

    实验目的 通过nginx实现反向代理的功能,类似apache反向代理和haproxy反向代理 工作中用nginx做反向代理和负载均衡的也越来越多了 有些公司从web服务器到反向代理,都使用nginx. ...

  10. 阿里低代码引擎 | LowCodeEngine - 如何配置并调用请求

    首发于 语雀文档@blueju 前言 发送请求是前端中很重要也很常见的一部分,阿里低代码引擎自然也不会缺少这一块.在阿里低代码引擎中,请求是在数据源中配置,数据源位置如下图: 配置 配置界面如下图:其 ...