1005 Spell It Right (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

注意:题中有一个case是0

 #include<iostream>
#include<string>
#include<stack> using namespace std; string numEnglish[] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; int main()
{
string str;
int sum = ;
stack<int> s; getline(cin,str); for(int i=;i<str.size();++i)
sum += str[i]-; if(sum == )
cout<<"zero"<<endl;
else
{
while(sum)
{
s.push(sum%);
sum /= ;
} cout<<numEnglish[s.top()];
s.pop(); while(!s.empty())
{
cout << " " << numEnglish[s.top()];
s.pop();
}
} return ;
}
 

PAT 甲级 1005 Spell It Right (20 分)的更多相关文章

  1. PAT 甲级 1005 Spell It Right (20)(代码)

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...

  2. PAT 甲级 1005. Spell It Right (20) 【字符串】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...

  3. Day 006:PAT练习--1005 Spell It Right (20 分)

    上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...

  4. PAT Advanced 1005 Spell It Right (20 分)

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

  5. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...

  6. 1005 Spell It Right (20分)

    1005 Spell It Right (20分) 题目: Given a non-negative integer N, your task is to compute the sum of all ...

  7. PAT甲级:1152 Google Recruitment (20分)

    PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...

  8. PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏

    1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  9. PAT 甲级 1041 Be Unique (20 分)

    1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...

随机推荐

  1. redis可执行文件说明

    redis-server    :redis服务器 redis-cli    :redis命令客户端 redis-benchmark    :redis性能压测工具 redis-check-dump ...

  2. libdl.so 动态库加载、查找

    使用libdl.so库 动态库加载原理   动态库中函数的查找已经封装成 libdl.so,有4个函数: dlopen  : 打开一个动态库 dlsym   : 在打开的动态库里找一个函数 dlclo ...

  3. 手把手教你实现一个 Vue 进度条组件!

    最近在个人的项目中,想对页面之间跳转的过程进行优化,想到了很多文档或 npm 等都用到的页面跳转进度条,于是便想自己去实现一个,特此记录. 来看下 npm 搜索组件时候的效果: so 下面咱们一起动手 ...

  4. CHECK约束表达式

    1.性别:只能填写'男'和'女' (字段名='男'or 字段名='女') 注意:单引号里的值可以为其他任何字 2.规定密码长度不能小于6位数 (len([字段名])>(5))   3.例:成绩在 ...

  5. 史上最简单OpenGL+VS2017环境配置

    这里采用 最简单的方法: (1)添加Nuget包管理器(方便我们为项目添加OpenGL的库) (2)新建一个项目 右键我们的项目名 ——> 管理NuGet程序包——>搜索nupengl,然 ...

  6. mongodb初步使用体验

    前言 Mongodb是一个非常有名的缓存数据库,和它名气相当的还有redis和hbase.笔者之前使用过redis,memcache和elasticsearch,借着工作机会,正好可以好好学习一下mo ...

  7. 剑指Offer 49. 把字符串转换成整数 (字符串)

    题目描述 将一个字符串转换成一个整数(实现Integer.valueOf(string)的功能,但是string不符合数字要求时返回0),要求不能使用字符串转换整数的库函数. 数值为0或者字符串不是一 ...

  8. RSA加密解密实现(JAVA)

    1.关于RSA算法的原理解析参考:http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html 2.RSA密钥长度.明文长度和密 ...

  9. 移动web总结

    Meta标签:   1 <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-sc ...

  10. Python学习二十八周(vue.js)

    一.指令 1.一个例子简单实用vue: 下载vue.js(这里实用1.0.21版本) 编写html代码: <!DOCTYPE html> <html lang="en&qu ...