题干:

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 (≤10​100​​).

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

解题报告:

考察就是递归输出而已。注意输出格式的控制。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
ll ans;
char s[MAX];
char db[10][102] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
void out(ll x) {if(x <= 9) printf("%s",db[x]);else {out(x/10); printf(" %s",db[x%10]);}
}
int main()
{cin>>s+1;int len = strlen(s+1);for(int i = 1; i<=len; i++) {ans += s[i] - '0';}out(ans);return 0;
}

【PAT - 甲级1005】Spell It Right (20分) (递归输出,水题)相关推荐

  1. PAT甲级 -- 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】1005 Spell It Right (20 分)——字符串处理

    //要么处理字符串,要么就数字分解,都想到了没有有效组合 //我的解法1:加法结果还是int,最后逆序分解数字,按序插入#include <iostream> #include <s ...

  3. PAT甲级1005 Spell it Right 【20】【字符串操作】

    1005 Spell It Right (20分) 题目要求 Given a non-negative integer N, your task is to compute the sum of al ...

  4. PAT甲级1005 Spell It Right :[C++题解]字符串处理

    文章目录 题目分析 题目链接 题目分析 ac代码 #include<bits/stdc++.h> using namespace std;const int N =110;string n ...

  5. PAT甲级 1027 Colors in Mars (20分)

    1027 Colors in Mars (20分) 题目链接:PAT A 1027 题目大意:给出三个十进制数,都是在[0-168]范围内,要求将他们转化为13进制后按顺序输出. 思路分析:非常简单的 ...

  6. PAT甲级 -- 1148 Werewolf - Simple Version (20 分)

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

  7. 1005 Spell It Right (20 分)——13行代码Ac

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given a non-negative integer N, your task is to compute the sum o ...

  8. 【PAT甲级 StringBuilder的使用】1005 Spell It Right (20 分) Java版 7/7通过

    题目 挺简单的,是个水题 坑 & 心得 一开始switch (i)忘了写case 0的情况,导致两个测试点没通过,不过很快就发现了 int 类型的 sum 转换为 str 的方式:用空字符串拼 ...

  9. 【PAT (Advanced Level) Practice】1005 Spell It Right (20 分)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<string> #incl ...

  10. 【PAT甲级 约会】1061 Dating (20 分) C++ 全部AC

    题目 这个题要注意的细节很多.因为一个星期有七天,一天有24小时,所以要注意字母范围这个隐藏条件,不符合条件的字母要跳过. 还要注意:第二次查找,要接着第一次找到的位置开始找.这个有点坑,题目里没说明 ...

最新文章

  1. pywinauto 记事本操作示例 移动鼠标 使用键盘 自动操作软件
  2. 目标检测-基于Pytorch实现Yolov3(1)- 搭建模型
  3. node 压缩图片_为了你安全压缩图片我操碎了心
  4. 抽象的(abstract)方法是否可同时是静态的(static), 是否可同时是本地方法 (native),是否可同时被 synchronized
  5. freemarker中遇到null报错的处理方法
  6. 浅析Kerberos原理,及其应用和管理
  7. linux与磁盘相关的内容
  8. base64转化字节流 js_js - blob流和base64,以及file和base64的相互转换
  9. hdoj 3400 三分
  10. ERP技术在财务信息化转型中应用探讨
  11. 学习spring第一天
  12. hexo发布后样式丢失
  13. Wordpress淘宝客专用链接跳转插件Pretty Link Lite
  14. 小程序发布文章-微信小程序视频教程28
  15. 华为安全 HCIP 723题库+知识点
  16. OpenLayers 6 代码绘制/draw交互组件绘制两种方式绘制椭圆过程详解
  17. 视频号拍摄技巧和制作方法有哪些?
  18. java 栅栏_Java 并发工具类(栅栏 CyclicBarrier )
  19. Android传感器(三):方向传感器
  20. 四个锻炼方法腰椎间盘突出症全治好

热门文章

  1. uva11991 Easy Problem from Rujia Liu?
  2. flex常见问题归纳
  3. PAT-1127. ZigZagging on a Tree (30)
  4. 大学python笔记_Python 上手笔记
  5. 弹弹堂sf发布网_私服冒险岛,新开私服冒险岛,心动sf冒险岛发布网,最新开的私服冒险岛应该如何快速的获取魅力呢?...
  6. hadoop 计算几点 主节点_01-Hadoop的介绍
  7. MySQL求类型为GX的平均积分_mysql基本操作
  8. X210烧写linux系统
  9. 十六进制除法运算法则_苏教版数学七年级上册 微课视频 2.6 有理数的乘法与除法(1)...
  10. matlab表达式部分项求和,matlab如何得到符号表达式中某一部分项的系数