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 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 (≤10100).
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
注意:题中有一个case是0
#include<iostream>
#include<string>
#include<stack> using namespace std; string numEnglish[] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; int main()
{
string str;
int sum = ;
stack<int> s; getline(cin,str); for(int i=;i<str.size();++i)
sum += str[i]-; if(sum == )
cout<<"zero"<<endl;
else
{
while(sum)
{
s.push(sum%);
sum /= ;
} cout<<numEnglish[s.top()];
s.pop(); while(!s.empty())
{
cout << " " << numEnglish[s.top()];
s.pop();
}
} return ;
}
PAT 甲级 1005 Spell It Right (20 分)的更多相关文章
- 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 ...
- Day 006:PAT练习--1005 Spell It Right (20 分)
上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...
- 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 (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- 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 ...
- PAT甲级:1152 Google Recruitment (20分)
PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...
- 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 ...
- PAT 甲级 1041 Be Unique (20 分)
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...
随机推荐
- 漏洞复现——httpd换行解析漏洞
漏洞原理: 在解析php文件时,1.php\x0A这种格式的文件将会被认为php文件解析,进而可以绕过一些服务器的安全策略. 漏洞版本: 2.4.0~2.4.29 漏洞复现: 复现该漏洞是利用dock ...
- UVa 10905 - Children's Game 排序,题目没有说输入是int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- python if __name__=='__main__'的理解
定义一个模块叫module.py: def main(): print "we are in %s" %__name__ if __name__=='__main__': main ...
- python笔记14-三元运算符
a = 1b = 2#下面这个c = a if a>1 else b #和下面是一样的效果if a > 1: c = aelse: c = b #打印偶数s=[]nums = list(r ...
- python笔记9-字符串操作
1.定义字符串 字符串有下标从0开始,用[]可以来取下标 2.字符串读取 字符串可以使用循环for,每次取一个取出,循环对象的每个元素 3.字符串修改-字符串不可修改 字符串是不可变变量,一旦定义就不 ...
- L332 NBA: Dwyane Wade and Dirk Nowitzki Say Emotional Goodbyes
Two games in the NBA ended amid emotional scenes on Tuesday as legends at separate teams marked thei ...
- nodejs -- event 模块, 事件模块.
1. 注册事件 on 或者 addListener,触发事件 emit 1-1简单的使用: var EventEmitter = require('events').EventEmitter; var ...
- pthon入门之strip()和split()函数简单区分
小白,分享记录学习新感悟 路飞的第一次作业写一个登录的程序,作业的升级需求中有个锁文件的需求,大致上如果用户数错了密码三次将用户写到黑名单上,下次登录锁定: ok基本的要求写完,我们上代码 usern ...
- FreeSWITCH添加中文语音
1.准备中文语音包 可以到freeswitch官网下载,也可以自己录制 2.中文资源的安装路径: 英文资源的路径为conf/sounds/en/us/callie/... 类似的设置中文资源的路径 ...
- canvas画圆类似于锯齿指针 angular5
拿到图的时候大致是这样的,里面的圆是有动态效果的,考虑到gif图耗资源,于是想要用canvas画出来: 仔细看图不难发现,这个锯齿圆类似于表盘,计算好弧度,不难实现: 因为项目现在用的框架是angul ...