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 ...
随机推荐
- django定义模型类-14
目录 1. 定义 字段类型 约束类型 django的模型类定义在应用下的 models.py 文件中. 模型类继承自 django.db.models 包下的 Model 类. 新创建应用 book ...
- Ruby中区分运行来源的方法(转)
Ruby中区分运行来源的方法 这篇文章主要介绍了Ruby中区分运行来源的方法,本文讲解的是类似Python中的if name == 'main':效果,其实Ruby中也有类似语法,需要的朋友可以参考下 ...
- RandomAccessFile java
RandomAccessFile 用来支持读写随机存取文件的类.提供“文件指针”,类似于游标和下标,使用getFilePointer()方法获得,利用seek()方法设置下标. public Rand ...
- CentOS7和OpenStack的笔记(一)
CentOS7和OpenStack的笔记(一) 最近搞CentOS7系统和OpenStack框架,整了近一个星期,系统装了好几次,框架搭了又从搭.虽然最后的实例没能启动成功,但是在这专研的一个星期里, ...
- pytorch之Tensor
#tensor和numpy import torch import numpy as np numpy_tensor = np.random.randn(3,4) print(numpy_tensor ...
- 20155209林虹宇虚拟机的安装及一点Linux的学习
预备作业3 虚拟机的安装 首先,我先了解了一下Linux和安装虚拟机的有关常识. Linux:Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支 ...
- 人脸识别引擎SeetaFaceEngine中Detection模块使用的测试代码
人脸识别引擎SeetaFaceEngine中Detection模块用于人脸检测,以下是测试代码: int test_detection() { std::vector<std::string&g ...
- log4j 注意事项
因为项目是 ssm+maven 所以有关log4j的注意事项记录一下 首先,需要在web.xml里配置spring的拦截器用于支持在项目下生成log4j日志文件 <!-- 配置log4j输出日志 ...
- jaron插件的用法
一.dict字典插件的基本用法: <%@ taglib prefix="dict" uri="http://www.evan.jaron.com/tags/dict ...
- 用原生JS实现的一个导航下拉菜单,下拉菜单的宽度与浏览器视口的宽度一样(js+html+css)
这个导航下拉菜单需要实现的功能是:下拉菜单的宽度与浏览器视口的宽度一样宽:一级导航只有两项,当鼠标移到一级导航上的导航项时,相应的二级导航出现.在本案例中通过改变二级导航的高度来实现二级导航的显示和消 ...