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

显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为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. k8s集群Job Pod 容器可能因为多种原因失效,想要更加稳定的使用Job负载,有哪些需要注意的地方?

    k8s集群Job Pod 容器可能因为多种原因失效,想要更加稳定的使用Job负载,有哪些需要注意的地方? 面试官:"计数性Job默认完成模式是什么?Indexed模式如何发布自定义索引呢?& ...

  2. RenderDoc图形调试器详细使用教程(基于DirectX11)

    前言 由于最近Visual Studio的图形调试器老是抽风,不得不寻找一个替代品了. 对于图形程序开发者来说,学会使用RenderDoc图形调试器可以帮助你全面了解渲染管线绑定的资源和运行状态,从而 ...

  3. 如果一个 linux 新手想要知道当前系统支持的所有命令的列表,他需要怎么做?

    使用命令 compgen -c,可以打印出所有支持的命令列表. [root@localhost ~]$ compgen -cl.lllswhichifthen elseelifficaseesacfo ...

  4. 什么是 Netflix Feign?它的优点是什么?

    Feign 是受到 Retrofit,JAXRS-2.0 和 WebSocket 启发的 java 客户端联编程序. Feign 的第一个目标是将约束分母的复杂性统一到 http apis,而不考虑其 ...

  5. Java并发机制(6)--阻塞队列

    Java并发编程:阻塞队列整理自:博客园-海子-http://www.cnblogs.com/dolphin0520/p/3933404.html 1.什么是阻塞队列 除了同步容器(Hashtable ...

  6. 在 Spring中如何注入一个java集合?

    Spring提供以下几种集合的配置元素: 类型用于注入一列值,允许有相同的值. 类型用于注入一组值,不允许有相同的值. 类型用于注入一组键值对,键和值都可以为任意类型. 类型用于注入一组键值对,键和值 ...

  7. Python使用pip安装No matching distribution found for PyYaml==5.3.1

    ERROR: Command errored out with exit status 1: command: /usr/local/dmahz/p_book_data/bin/python3.9 - ...

  8. 四、Springboot+jpa+mycat应用

    一.后台配置文件 # 连接地址 url: jdbc:mysql://127.0.0.1:8066/CHUNK?useUnicode=true&characterEncoding=utf-8&a ...

  9. springboot-数据访问之jdbc

    官网的starthttps://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-starter 111 ...

  10. LVS 工作图

    一.工作模式 1.NAT模式 -----主要是修改目标IP地址为RS的IP地址.即请求进入负载均衡器时做DNAT,响应出负载均衡器时做SNAT. 工作方式: 1)客户端请求网站,经过路由器到达负载均衡 ...