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 ...
随机推荐
- C语言中赋值表达式的返回值是什么?
我们或多或少都有过,或者见过将赋值表达式参与运算的情况.这通常会伴随着一些意想不到的问题.今天我就见到了一段奇怪的代码: #include<stdio.h> int main() { ; ...
- Linux系统下连接校园网Drcom客户端教程(广东工业大学)
这篇教程写给想要学习Linux系统或者在Linux系统下有需要使用Drcom上网的同学,在我疯狂踩坑,经过n多次的刷机装机实验,体验不同发行版本的linux系统后,终于懂得怎么连接上drcom,想想连 ...
- 旭日图(sunburst chart)绘制:R语言 & excel
旭日图(sunburst chart)也叫太阳图,一种圆环镶接图,每一个圆环就代表了同一级别的比例数据,离原点越近的圆环级别越高,最内层的圆表示层次结构的顶级.除了圆环外,旭日图还有若干从原点放射出去 ...
- PL/SQL轻量版(四)——存储函数/存储过程与触发器
概述 ORACLE 提供可以把 PL/SQL 程序存储在数据库中,并可以在任何地方来运行它.这样就叫存储过程或函数.过程和函数统称为 PL/SQL 子程序,他们是被命名的 PL/SQL 块,均存储在数 ...
- 20155206 2016-2017-2 《Java程序设计》第三周学习总结
20155206 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 两个基本标准类:java.util.Scanner , java.math.BigDecim ...
- 2017-2018-1 20155232 《信息安全系统设计基础》第四周学习总结以及课上myod练习补充博客
2017-2018-1 20155232 <信息安全系统设计基础>第四周学习总结以及课上myod练习补充博客 课上myod练习 1 参考教材第十章内容 2 用Linux IO相关系统调用编 ...
- 20155235 2016-2017-2《Java程序设计》课程总结
每周作业链接汇总 预备作业一:学期前作业 预备作业二:技能获取与C语言学习情况 预备作业三:安装虚拟机与Linux的学习 第一周作业:20155235 2006-2007-2 <Java程序设计 ...
- 20155301 2016-2017-2 《Java程序设计》第1周学习总结
20155301 2016-2017-2 <Java程序设计>第1周学习总结 教材学习内容总结 Java SE的全称是Java Platform, Standard Edition,并用于 ...
- 20155313 实验二《Java面向对象程序设计》实验报告
20155313 实验二<Java面向对象程序设计>实验报告 一.实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. ...
- P,NP,NPC的通俗解释
这或许是众多OIer最大的误区之一. 你会经常看到网上出现“这怎么做,这不是NP问题吗”.“这个只有搜了,这已经被证明是NP问题 了”之类的话.你要知道,大多数人此时所说的NP问题其实都是指的N ...