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 (≤).

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 <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <stack>
using namespace std;
string s;
void _print(int x)
{
stack<int> s;
while(x){
s.push(x%);
x/=;
}
while(!s.empty()){
switch(s.top()){
case : cout<<"zero"; break;
case : cout<<"one";break;
case : cout<<"two";break;
case : cout<<"three";break;
case : cout<<"four";break;
case : cout<<"five";break;
case : cout<<"six";break;
case : cout<<"seven";break;
case : cout<<"eight";break;
case : cout<<"nine";break;
}
s.pop();
if(!s.empty()) cout<<" ";
}
cout<<endl;
}
int main()
{
while(cin>>s){
int sum=;
for(int i=;i<s.length();i++){
sum+=int(s[i]-'');
}
if(sum==) cout<<"zero"<<endl;
else _print(sum);
}
return ;
}

PAT (Advanced Level) Practice 1005 Spell It Right (20 分) (switch)的更多相关文章

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

  2. PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...

  3. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  4. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...

  5. PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...

  6. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  7. PAT (Advanced Level) Practice 1027 Colors in Mars (20 分)

    People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...

  8. PAT (Advanced Level) Practice 1054 The Dominant Color (20 分)

    Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of i ...

  9. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) (找最值)

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

随机推荐

  1. ansible实现SSH配置免密互信

    Ansible是用来处理大批量重复性操作的工具,只需要在一台机器上就可以远程控制所有机器,但前提是必须保证每台机器之间SSH可以相互免密登录.关于Ansible的安装和环境准备请参考Ansible环境 ...

  2. 20200105--python学习数据类型总结

    总结 python中的数据类型:整型/布尔类型/字符串/元组/列表/字典/集合 注意:列表,字典,集合都不能作为字典中的key,也不能作为集合中的元素 数据类型: (1)整型 (2)布尔类型:只有两个 ...

  3. php面试笔记(5)-php基础知识-自定义函数及内部函数考点

    本文是根据慕课网Jason老师的课程进行的PHP面试知识点总结和升华,如有侵权请联系我进行删除,email:guoyugygy@163.com 在面试中,考官往往喜欢基础扎实的面试者,而函数相关的考点 ...

  4. 《自拍教程17》Python调用命令

    他山之石 何为他山之石,就是借助外界工具,来实现自己想要的功能. 命令行界面软件, 即各种命令,我们也叫命令行工具, 此类工具也是测试人员或者开发人员常用的工具的一种. 测试人员可以借助这类工具,快速 ...

  5. mongoDB常用命令与安全加固

    一.介绍 MongoDB 是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案.MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系 ...

  6. PYTHON 学习笔记4 模块的使用、基本IO 写入读取、JSON序列化

    前言 若在之前写代码的方式中,从Python 解释器进入.退出后再次进入,其定义的变量.函数等都会丢失.为了解决这个为,我们需要将需要的函数.以及定义的变量等都写入一个文件当中.这个文件就叫做脚本 随 ...

  7. js中的innerHTML,innerText,value的区别

    首先先说一下 我自己认为的 innerHTML,innerText,value的区别 innerHTML 是在控件中加html代码 就是设置一个元素里面的HTML eg: <html> & ...

  8. 【idea激活码】,【WebStorm激活码】,【DataGrip激活码】,【IntelliJ 全家桶系列】,【定期更新】,【第一期】

    IntelliJ IDEA.PyCharm.PhpStorm.WebStorm.RubyMide.AppCode.CLion.GoLand.DataGrip.Rider.Android Studio可 ...

  9. nginx location展示及文件共享

    nginx 目录展示及文件访问 效果: [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-d5G9wfKK-1570116907804)(E:\Users\FangJunX ...

  10. idea 工具 听课笔记 首页

    maven 创建 javaWeb站点结构标准及异常权限调整 解决Intellij Idea下修改jsp页面不自动更新(链接 idea中使用github  提交 idea 从github.com上恢复站 ...