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 ...
随机推荐
- Delphi2010中DataSnap技术
文章来源: https://blog.csdn.net/xieyunc/article/details/47865227?_t_t_t=0.3049736963513836 一.为DataSnap系统 ...
- STL 迭代器 iterator const
STL迭代器很多时候可以当成指针来使用. 但是指针一般可以用const来控制访问. 那迭代器呢. #include <iostream> #include <vector> u ...
- JS-几大排序算法(更新中...)
关于排序都会讲的名词:(我自己的理解) 时间复杂度: 指排序过程中,程序消耗的时间. 空间复杂度: 指排序过程中,程序所消耗内存的大小. 稳定: 如果两个值相等,a和b,a=b且a在b位置的左边,排序 ...
- 深入学习Make命令和Makefile(下)
https://www.zybuluo.com/lishuhuakai/note/209300 make是Linux下的一款程序自动维护工具,配合makefile的使用,就能够根据程序中模块的修改情况 ...
- Redis学习笔记--Redis配置文件redis.conf参数配置详解
########################################## 常规 ########################################## daemonize n ...
- javascript 原型世界浅析
一. 无中生有 起初,什么都没有. 造物主说:没有东西本身也是一种东西啊,于是就有了null: 现在我们要造点儿东西出来.但是没有原料怎么办? 有一个声音说:不是有null嘛? 另一个声音说:可是nu ...
- Android MediaScanner
一.MediaScanner 的使用 1)Intent.ACTION_MEDIA_SCANNER_SCAN_FILE:扫描指定文件 public void scanFileAsync(Context ...
- 网卡bonding模式 - bond0、1、4配置
网卡bonding模式 - bond0.1.4配置 网卡bonding简介 网卡绑定就是把多张物理网卡通过软件虚拟成一个虚拟的网卡,配置完毕后,所有的物理网卡的ip和mac将会变成相同的.多网卡同时工 ...
- Redmine插件的安装与卸载,知识库插件安装。
本文介绍linux版本的Redmine插件安装,通常Redmine安装在Linux系统,/var/www/redmine/路径. 安装: 复制插件到 2.X版本 #{RAILS_ROOT}/plugi ...
- jdbc(1)(三)DBCP、C3P0、Proxool 、 BoneCP开源连接池的简介
简介 使用评价 项目主页 DBCP DBCP是一个依赖Jakarta commons-pool对象池机制的数据库连接池.DBCP可以直接的在应用程序用使用 可以设置最大和最小连 ...