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:

  1. 12345

Sample Output:

  1. one five
  2.  
  3. 思路:求和,英文输出,但是需要注意特殊情况:零的时候。
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <cstring>
  5. #include <cstdio>
  6. #include <stack>
  7. using namespace std;
  8. string s;
  9. void _print(int x)
  10. {
  11. stack<int> s;
  12. while(x){
  13. s.push(x%);
  14. x/=;
  15. }
  16. while(!s.empty()){
  17. switch(s.top()){
  18. case : cout<<"zero"; break;
  19. case : cout<<"one";break;
  20. case : cout<<"two";break;
  21. case : cout<<"three";break;
  22. case : cout<<"four";break;
  23. case : cout<<"five";break;
  24. case : cout<<"six";break;
  25. case : cout<<"seven";break;
  26. case : cout<<"eight";break;
  27. case : cout<<"nine";break;
  28. }
  29. s.pop();
  30. if(!s.empty()) cout<<" ";
  31. }
  32. cout<<endl;
  33. }
  34. int main()
  35. {
  36. while(cin>>s){
  37. int sum=;
  38. for(int i=;i<s.length();i++){
  39. sum+=int(s[i]-'');
  40. }
  41. if(sum==) cout<<"zero"<<endl;
  42. else _print(sum);
  43. }
  44. return ;
  45. }

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. Linux相关知识笔记

    Quagga要在linux下编译并配置运行,所有,学习一点linux的基础知识. 安装的Ubuntu,用户名linux,密码1 使能Ubuntu的IP转发功能,需要修改etc/sysctl.conf和 ...

  2. 无线网络WPA加密算法基础

    2013-11-13 23:08 (分类:网络安全) 对无线没什么认识,总听说有人蹭网,还有卖蹭网器的,于是补充一下知识. 无线加密有两类:WEP WAP,目前采用WEP加密的非常少了,WEP应该只是 ...

  3. 简单ts文件结构

    一.ts文件结构 DEMO{ 1. .vscode:特有文件夹,调试的配置文件,启动浏览器 2. Js:放ts编译后的文件,不管 3. Ts:放ts文件,敲代码 4. tsconfig.json:ts ...

  4. Django设置异步任务

    1.安装Django-celery 包:pip install django-celery==3.2.2 2.开启redis服务 需要使用redis做broker,所以在使用异步和定时任务时需要开启r ...

  5. linux中find文件搜索命令

    find 解释 命令名称:find 命令所在路径:/bin/find 执行权限:所有用户 功能描述:文件搜索 语法 find [搜索范围] [匹配条件] 匹配条件: -name 文件名(区分大小写) ...

  6. StarUML之八、StarUML的Entity-Relationship Diagram(实体关系图)示例

    数据库表关系设计也是常有场景,本章介绍如何设计一个实体关系图 1:新建项目,在Model Explore中Add Diagram | ER Diagram到指定的元素中: 2:从Toolbox中创建E ...

  7. position属性值4缺一带你了解相对还是绝对抑或是固定定位

    阿基米德说“给我一个支点,我能翘起整个地球”,在HTML页面中,给你一个坐标,可以把任何一个元素定位目标点,这就是定位!CSS有三种基本的定位机制:相对定位.绝对定位.固定定位,决定定位的positi ...

  8. 常用类String的总结

    /* String:字符串,使用一对""引起来表示. 1.String声明为final的,不可被继承 2.String实现了Serializable接口:表示字符串是支持序列化的. ...

  9. P1651 塔

    ----------------- 链接:Miku ----------------- 这是一道dp题,我么很容易发现这点. 数据范围很大,如果直接用两个塔的高度当状态,很危险,我们就必须要考虑一下优 ...

  10. opencv —— HoughCircles 霍夫圆变换原理及圆检测

    霍夫圆变换原理 霍夫圆变换的基本原理与霍夫线变换(https://www.cnblogs.com/bjxqmy/p/12331656.html)大体类似. 对直线来说,一条直线能由极径极角(r,θ)表 ...