PAT 甲级 1005 Spell It Right
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的更多相关文章
- 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 ...
- 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 甲级 1005. Spell It Right (20) 【字符串】
题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...
- 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 ...
- 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 ...
- Day 006:PAT练习--1005 Spell It Right (20 分)
上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...
- PAT甲级1005水题飘过
题目分析:用一个字符串输入之后遍历每一位求和后,不断%10获取最后一位存储下来,逆序用对应的英文单词输出(注意输入为0的情况) #include<iostream> #include< ...
- 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 ...
- 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 ...
随机推荐
- mysql 日志log
my.ini log-error=D:/phpStudy/PHPTutorial/MySQL/log/error.loglog=D:/phpStudy/PHPTutorial/MySQL/log/my ...
- 一个没有成就而即将退赛的OIer的告别书
期末考试成绩出来了. 我也知道混在这个班的时间不长了. 尽管如此,我觉得父母的意见是正确的,我确实不适合OI.所以我会成为省三都没有的一个OIer. 我不后悔,因为曾经是我自己错了. 我感谢遇到了好的 ...
- 有限差分法解矩形波导内场值、截止频率 MATLAB
利用有限差分法,解矩形波导内场解和截止频率: 这里以解TM11模为例,利用双重迭代法,每4次场值,更新一次Kc: %% % 求矩形波导中TM11模 截面内场分布.截止频率kc和特性阻抗Zc % // ...
- 鼠标移动在屏幕上显示温度Tip提示功能-CToolTipCtrl类的使用
初学VC++,太多知识不懂,需要不断的查找资料,想通过记录让自己有所积累,主要是怕以后会很快忘记.最近在做一个在屏幕上显示鼠标移动位置的温度值,我利用先缓存一帧图像的温度值,然后,通过鼠标移动消息相应 ...
- 20155232 2016-2017-3 《Java程序设计》第4周学习总结
20155232 2016-2017-3 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 继承与多态 所谓继承就是避免多个类间重复定义共同行为. 1.重复在程序设计上就是不好 ...
- 20155302 2016-2017-2 《Java程序设计》 第1周学习总结
20155302 2016-2017-2 <Java程序设计> 第1周学习总结 教材学习内容总结 浏览全书提出问题 chapter1:怎么保证现在系统在用最高版本的JRE呢?在哪里查看及升 ...
- libuv源码分析
项目开发过程中经常使用了基于libuv库封装的库接口来实现异步处理,一直没仔细研究过这些接口的内部如何实现,因此也就没有掌握它的设计思想.今天花了点时间研究了其事件循环内部的一些过程,总算有了一些理解 ...
- 记Thinkpad的一次扩容升级经历
俗话说:" 工欲善其事,必先利其器" 阅读目录: 背景 目标 准备 友情提示 制作引导盘 分区及备份 拆机装盘 重装系统 写在结束的 参考资料 背景: 作为一个近六年的IT从业Co ...
- JavaScript学习笔记(三)——对象
第四章 理解对象 1 说明 对象的状态:属性,行为:方法: 对象定义放在花括号内: 用冒号分隔属性名和属性值: 用逗号分隔属性名和属性值对,包括方法: 最后一个属性值后面不加逗号: 属性名可以是任何字 ...
- HPUX 配置zabbix开机自动启动
1. 在/etc/rc.config.d目录下创建zabbixd文件,并增加以下内容: #!/sbin/sh # v1.0 ?zabbixd startup/kill config ...