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. coroutine - yield from

    yield from yield from x 表达式对 x 对象所做的第一件事是,调用 iter(x),从中获取迭代器.因 此, x 可以是任何可迭代的对象. 可是,如果 yield from 结构 ...

  2. 使用chrome控制台调试js代码

    1.打开控制台(空白页签即可) 2.将控制台在独立页打开(点击控制台右上角的三个点图标,然后点击如下图中的图标) 3.创建脚本编辑页面 4.页面区域说明 5.花键+回车之行代码 6.常用命令介绍 6. ...

  3. C#在窗体中按下鼠标键拖动窗体

    [DllImport("user32.dll")]//拖动无窗体的控件 public static extern bool ReleaseCapture(); [DllImport ...

  4. RTEMS进程同步机制

    互斥量 好像没有互斥量,信号量接收那儿有个图,互斥量似乎术语一类特殊的信号量. 信号量 12. Semaphore Manager 12.1. Introduction The semaphore m ...

  5. chkcongfig 命令

    chkconfig   命令主要用来  更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig ...

  6. js—数组那些事儿

    数组维度升级 创建一维数组 //创建一维数组 var a=[]; var b=new Array(); var c=[1,2,'w']; var d=[1,2,[1,2]]; 创建二维数组 var c ...

  7. 1.3.5 详解项目中的资源——Android第一行代码(第二版)笔记

    所有以drawable开头的文件夹都是用来存放图片的. 所有以mipmap开头的文件夹都是用来存放应用图标的 所有以values开头的文件夹都是用来存放字符串.样式.颜色等配置的, layout文件夹 ...

  8. 类加载机制与JVM调优命令

    一.类加载过程 类加载:类加载器将.class字节码文件加载进Java虚拟机的内存中. 加载:在硬盘上查找并通过IO读入字节码文件 连接:执行校验.准备.解析(可选)步骤 校验:校验字节码文件的正确性 ...

  9. C# 调用WCF服务的两种方法

    项目简介 之前领导布置一个做单点登录的功能给我,实际上就是医院想做一个统一的平台来实现在这个统一的平台登录后不需要在His.Emr.Lis等系统一个个登录,直接可以登录到对应的系统,然后进行相应的操作 ...

  10. CSP2019第二轮-划水游记

    又是 颓废的 一年 眨眼间已经初三了 到了NOIPCSP的时节 Day0 学校(没错,全校事件)抽风地把二晚停了,于是也就有了机会早早回家van♂耍 和母上大人简单地收拾收拾东西,回了姥姥家 以&qu ...