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 ...
随机推荐
- SQL Server设置登录验证模式
我们在安装SQL Server的时候可以设置“混合验证模式”,既可以使用windows身份验证登录,也可以使用SQL Server身份验证登录. 如果我们在安装的时候并未设置"混合验证模式& ...
- c++ ::开头
std::string 表示std命名空间下的 string类.直接::开始,表示顶层命名空间(全局变量)std::string -> ::std::string 这样也可以.::和 文件路径的 ...
- 异常:Servlet class X is not a javax.servlet.Servlet
使用Maven命令 mvn archetype:create 创建了一个简单的web项目.导入Eclipse运行时,报这样的异常信息: Servlet class X is not a javax.s ...
- python之Tkinter控件学习
转载自 http://www.cnblogs.com/kaituorensheng/p/3287652.html#_label0 阅读目录 1. 产品介绍 2. 设计规划 3. 相关知识 4. 源码 ...
- Elasticsearch学习之深入搜索二 --- 搜索底层原理剖析
1. 普通match如何转换为term+should { "match": { "title": "java elasticsearch"} ...
- LeetCode 18 4Sum (4个数字之和等于target)
题目链接 https://leetcode.com/problems/4sum/?tab=Description 找到数组中满足 a+b+c+d=0的所有组合,要求不重复. Basic idea is ...
- VMware ESXI5.5 Memories limits resolved soluation.
在使用VMware ESXI5.5 的时候提示内存限制了,在网上找的了解决方案: 如下文: 1. Boot from VMware ESXi 5.5; 2. wait "Welcome to ...
- 3-1 vue-resource基础介绍
1.静态引用 <script src="https://cdn.bootcss.com/vue-resource/1.3.4/vue-resource.js">< ...
- 查看docker容器的IP地址
|awk '{print $2}' |tr '"' " " |tr ',' ' ' # 可以用容器id或名称 方法二: docker inspect --fo ...
- PS-CC常用快捷键总结
灵活使用photoshop软件快捷键是学好该软件的基础,ps快捷键对于ps平时操作有很大帮助 熟练掌握ps的快捷键可以为了处理图片节省很多时间.现在笔者将自己平时常用的快捷键总结如下: 移动工具[V] ...