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 [非常简单]的更多相关文章

  1. PAT(B) 1089 狼人杀-简单版(Java)逻辑推理

    题目链接:1089 狼人杀-简单版 (20 point(s)) 题目描述 以下文字摘自<灵机一动·好玩的数学>:"狼人杀"游戏分为狼人.好人两大阵营.在一局" ...

  2. PAT 1054 The Dominant Color[简单][运行超时的问题]

    1054 The Dominant Color (20)(20 分) Behind the scenes in the computer's memory, color is always talke ...

  3. PAT 1019 General Palindromic Number[简单]

    1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...

  4. PAT World Cup Betting[非常简单]

    1011 World Cup Betting (20)(20 分) With the 2010 FIFA World Cup running, football fans the world over ...

  5. PAT 1036 Boys vs Girls[简单]

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  6. PAT 1144 The Missing Number[简单]

    1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...

  7. PAT 1027 Colors in Mars[简单][注意]

    1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar w ...

  8. 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 ...

  9. PAT 1136 A Delayed Palindrome[简单]

    1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k+1 ...

随机推荐

  1. 【资源大全】.NET资源大全中文版(Awesome最新版)

    算法与数据结构(Algorithms and Data structures) 应用程序接口(API) 应用程序框架(Application Frameworks) 模板引擎(Application ...

  2. django进阶-小实例

    前言: 这篇博客对上篇博客django进阶作下补充. 一.效果图 前端界面较简单(丑),有两个功能: 从数据库中取出书名 eg: 新书A 在form表单输入书名,选择出版社,选择作者(多选),输入完毕 ...

  3. 【Shell脚本编程系列】Shell脚本开发的习惯和规范

    1.开头指定脚本解释器 #!/bin/sh或#!/bin/bash 2.开头加版本版权信息 #Date #Author #Mail #Function #Version 提示:可配置vim编辑文件时自 ...

  4. LeetCode 13 Roman to Integer(罗马数字转为整数)

    题目链接 https://leetcode.com/problems/roman-to-integer/?tab=Description   int toNumber(char ch) { switc ...

  5. 【CF840C】On the Bench DP

    [CF840C]On the Bench 题意:给你一个长度为n的数组{ai},定义一个1到n的排列是合法的,当且仅当对于$1\le i <n$,$a_i\times a_{i+1}$不是完全平 ...

  6. selenium中javascript调试

    之前写了使用js输入长文件的文章,有同事在使用时,发现竟然无法输入,也不知道是什么原因,且用的还是id方式. 在参考网文后,才发现是js写的有问题,现总结一下 javascript调试,在firefo ...

  7. Android ActivityManager与WindowManager

    <uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission ...

  8. html如何给图片加角标

    https://segmentfault.com/q/1010000006551803?_ea=1074082 <html><style> #a1 { width: 200px ...

  9. mousedown\mouseup\click事件关系

    背景分析: 如果用户在一个元素上点击,那么最少三个事件会被触发,事件发生顺序: 1.mousedown,当用户在这个元素上按下鼠标键的时候 2.mouseup,当用户在这个元素上松开鼠标键的时候 3. ...

  10. ZooKeeper (一)概览

    注:出于记录对 zookeeper 的学习研究成果目的,并分享经验,根据官方文档翻译整理而成本文,原文地址: http://zookeeper.apache.org/doc/trunk/zookeep ...