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 ...
随机推荐
- Win8交互UX——键盘交互
设计用户可以通过硬件键盘.屏幕键盘或触摸键盘交互的 Windows 应用商店应用. 本主题介绍键盘交互的设计注意事项.有关实现键盘交互的信息,请参阅响应键盘输入. 键盘交互 键盘输入是 Windows ...
- springbatch---->springbatch的使用(五)
这里我们介绍一个从数据库读取数据并写入到文件中的案例.如果能真心爱上一个人,那么不管对方是何等恶劣,哪怕对方并不爱自己,人生也至少不会是地狱,就算多少有点黯淡. 读取数据库数据 一.定义一个读写的jo ...
- Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/ This tut ...
- Elasticsearch学习之深入搜索四 --- cross-fields搜索
1. cross-fields搜索 一个唯一标识,跨了多个field.比如一个人,标识,是姓名:一个建筑,它的标识是地址.姓名可以散落在多个field中,比如first_name和last_name中 ...
- Linux上的ftp服务器vsftpd之配置满天飞--设置匿名用户访问(不弹出用户名密码框)以及其他用户可正常上传
一.问题背景 没事谁折腾这鬼玩意哦...还不是因为bug. 我们的应用,用户头像是存在ftp上的.之前的ftp服务器是一台windows,我们后台服务器程序收到用户上传头像的请求时,会用一个ROOT/ ...
- C# 读取xml时,遇到xmlns的问题
1.读取xml的时候,由于xml里有xmlns的属性,导致了读xml无法正常读取.通过网上搜索,发现需要先注册命名空间. xmlns是XML Namespaces的缩写,中文名称是XML(标准通用标 ...
- 23种设计模式之单例模式(Singleton)
单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例,这个类称为单例类,它提供全局访问的方法. public class SingleTon { private static Si ...
- node项目部署相关问题
process.env process.env属性返回一个对象,包含了当前Shell的所有环境变量. 通常的做法是,新建一个环境变量NODE_ENV,用它确定当前所处的开发阶段,生产阶段设为produ ...
- SDWebImage第三方库使用注意的一些问题
1.利用"UIImageView+WebCache.h"加载图片数据 例如: UIImage *placeHolderImg = [UIImage imageNamed:@&quo ...
- php----空字符串的和NULL的区别
空字符串和null的区别是非常的大的,虽然都是没有任何东西,但是空字符串会占据一个内存,只是在这里内存里面没有东西而已,但是null就是完全不存在这个东西,他是不会开辟内存. $str1 = &quo ...