PAT Spell It Right [非常简单]
1005 Spell It Right (20)(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 (<= 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 <iostream>
#include <cstring>
#include <cstdio>
#include<map>
#include<stack>
using namespace std;
string str[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
//{zero,one,two,three,four,five,six,seven,eight,nine};原来这些字符串在定义的时候都要加上双引号啊。
map<int,string> mp;
int main()
{ //freopen("1.txt","r",stdin);
string s;
cin>>s;
int n=s.size();
int sum=;
for(int i=;i<;i++){
mp[i]=str[i]; }
for(int i=;i<n;i++){
sum+=(s[i]-'');
} stack<string> sta;
//得到这个数之后还得倒序输出。那就用个栈吧。
int temp;
if(sum==)cout<<"zero";
while(sum!=){
temp=sum%;
sum/=;
sta.push(mp[temp]);
}
while(!sta.empty()){
cout<<sta.top();
sta.pop();
if(!sta.empty())
cout<<" ";
}
return ;
}
//这道题可以说是非常简单了,一看题目就很短,就是输入输出每位数相加后的和对应的英文。一开始提交的了19分,我就猜到是说如果输入0的话,我的程序没有输出,所以就加了一句如果是0,那么直接输出zero。emmm,已经两次碰到这样了,以后就直接考虑。加上这句之后就20分了。
PAT Spell It Right [非常简单]的更多相关文章
- PAT(B) 1089 狼人杀-简单版(Java)逻辑推理
题目链接:1089 狼人杀-简单版 (20 point(s)) 题目描述 以下文字摘自<灵机一动·好玩的数学>:"狼人杀"游戏分为狼人.好人两大阵营.在一局" ...
- PAT 1054 The Dominant Color[简单][运行超时的问题]
1054 The Dominant Color (20)(20 分) Behind the scenes in the computer's memory, color is always talke ...
- PAT 1019 General Palindromic Number[简单]
1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...
- PAT World Cup Betting[非常简单]
1011 World Cup Betting (20)(20 分) With the 2010 FIFA World Cup running, football fans the world over ...
- PAT 1036 Boys vs Girls[简单]
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 1144 The Missing Number[简单]
1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...
- PAT 1027 Colors in Mars[简单][注意]
1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar w ...
- PAT A+B for Polynomials[简单]
1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...
- PAT 1136 A Delayed Palindrome[简单]
1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k+1 ...
随机推荐
- Objective-c官方文档 怎么使用对象
版权声明:原创作品,谢绝转载!否则将追究法律责任. 对象发送和接受消息 尽管有不同的方法来发送消息在对象之间,到目前位置是想中括号那样[obj doSomeThing]:左边是接受消息的接收器,右 ...
- 【大数据系列】HDFS初识
一.HDFS介绍 HDFS为了做到可靠性(reliability)创建了多分数据块(data blocks)的复制(replicas),并将它们放置在服务集群的计算节点中(compute nodes) ...
- vue案例 - v-model实现自定义样式の多选与单选
接,上文:https://www.cnblogs.com/padding1015/p/9265985.html 这两天在玩mpvue,但是下午如果对着文档大眼瞪小眼的话,肯定会睡着的. 想起昨晚的fl ...
- 使用 Gogs 搭建自己的 Git 服务器
安装过程分为这些步骤: 新建用户: 下载源码编译 / 下载预编译二进制打包: 运行安装: 配置调整: 配置 nginx 反向代理: 保持服务运行: 注意,这里默认你已经安装好了 MySQL 服务器和 ...
- jenkins - svn: E170001报错的原因以及解决方案
1. 什么问题What? 使用Jenkins配置的svn拉取项目,Jenkins报错:svn: E170001; Your credentials to connect to the reposito ...
- Debian的自动化安装(DEBIAN_FRONTEND)
Debian 安装程序的参数 安装系统确认一些附加的引导参数 debconf/priority 这些参数设置将设置显示的信息为为最低的级别. 缺省安装使用 debconf/priority=high ...
- 微信小游戏 修改appid
微信开发者工具中,当你使用一个公众号开发一个项目,有需求切换到另外一个公众号继续开发时,需要修改appid. 修改微信小游戏 project.config.json 文件的appid
- 【咸鱼教程】Egret可长按识别二维码(精确位置和大小)
教程目录一 实现原理二 实现过程三 Demo下载 本教程是在Egret中实现长按识别的二维码,并可以精确定位二维码的位置和大小,支持横屏和竖屏. 一 实现原理 微信中长按识别二维码,需要长按jpg或p ...
- openstack 部署(Q版)-----环境准备篇
一.环境准备 系统:centos7 cinder01 内网:192.168.10.51 外网:172.16.1.51 compute01 内网:192.168.10.52 外网:172.16.1. ...
- Docker命令详解(build篇)
命令格式:docker build [OPTIONS] <PATH | URL | -> Usage: Build an image from a Dockerfile. 中文意思即:使用 ...