https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336

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

代码:
#include <bits/stdc++.h>
using namespace std; char s[1111], num[1111];
char a[20][50] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; void itoa(int x) {
if(x == 0) {
num[0] = '0';
num[1] = 0;
return ;
}
stack<int> st;
while(x) {
st.push(x % 10);
x = x / 10;
}
int sz = 0;
while(!st.empty()) {
num[sz++] = (char)(st.top() + '0');
num[sz] = 0;
st.pop();
}
} int main() {
scanf("%s", s);
int len = strlen(s);
int sum = 0;
for(int i = 0; i < len; i ++) {
sum += s[i] - '0';
} itoa(sum);
int lenum = strlen(num); for(int i = 0; i < lenum; i ++) {
printf("%s", a[num[i] - '0']);
printf("%s", i != lenum - 1 ? " " : "\n");
}
return 0;
}

  

PAT 甲级 1005 Spell It Right的更多相关文章

  1. 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 all th ...

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

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

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

  4. PAT甲1005 Spell it right【字符串】

    1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...

  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. Day 006:PAT练习--1005 Spell It Right (20 分)

    上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...

  7. PAT甲级1005水题飘过

    题目分析:用一个字符串输入之后遍历每一位求和后,不断%10获取最后一位存储下来,逆序用对应的英文单词输出(注意输入为0的情况) #include<iostream> #include< ...

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

  9. PAT甲级——A1005 Spell It Right

    题目描述 Given a non-negative integer N, your task is to compute the sum of all the digits of N, and out ...

随机推荐

  1. C语言进阶——基本数据类型01

    刚开始人们还没有数据类型这个概念,但是人们经常要使用到固定内存大小的内存,这个时候那时的程序员就要记录一段信息在内存中的起始位置和终止位置,很不方便,演变到后来就出现了数据类型这个概念 什莫是数据类型 ...

  2. MySQL高级——课程大纲

    一.课程概述 总体结构概述: //特别注意本次课程目标在于写出高效的JAVA代码,而非DBA等的专业调优 各章节概述         

  3. elasticsearch 安装问题

    Elasticsearch5.0 安装问题集锦 elasticsearch 5.0 安装过程中遇到了一些问题,通过查找资料几乎都解决掉了,这里简单记录一下 ,供以后查阅参考,也希望可以帮助遇到同样问题 ...

  4. SPOJ11469 SUBSET

    题面 Farmer John's owns N cows (2 <= N <= 20), where cow i produces M(i) units of milk each day ...

  5. .NET core 项目部署在windows 服务器方法以及iis 访问报 500.19错误的解决办法

    将本地发布的服务本地运行没问题,发布上云windows 服务器就报 500.19 0x8007000d 是因为云服务器没有安装.net core相关的插件,比如.NET CORE sdk等,请按照该文 ...

  6. angular中的$http服务

    $http是ng内置的一个服务.是简单的封装了浏览器原生的XMLHttpRequest对象. 写法1 $http({ method: "GET", url: 'data.json' ...

  7. Yii 2.0 中事件的使用

    关于PHP的事件处理,参照 http://www.cnblogs.com/mafeifan/p/4322238.html http://www.cnblogs.com/mafeifan/p/43222 ...

  8. Maven学习(九)-----定制库到Maven本地资源库

    这里有2个案例,需要手动发出Maven命令包括一个 jar 到 Maven 的本地资源库. 要使用的 jar 不存在于 Maven 的中心储存库中. 您创建了一个自定义的 jar ,而另一个 Mave ...

  9. Maven学习(七)-----Maven添加远程仓库

    Maven添加远程仓库 默认情况下,Maven从Maven中央仓库下载所有依赖关系.但是,有些库丢失在中央存储库,只有在Java.net或JBoss的储存库远程仓库中能找到. 1. Java.net资 ...

  10. ConfigurationProperties cannot be resolved to a type

    pom.xml 中报错之前: <parent> <groupId>org.springframework.boot</groupId> <artifactId ...