PAT (Advanced Level) Practice 1005 Spell It Right (20 分) (switch)
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)的更多相关文章
- 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 ...
- 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 ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 12-Java-myeclipse集成Tomcat步骤及Tomcat的使用步骤
一.了解Tomcat Tomcat是由Apache推出的一款免费开源的servlet容器/web应用服务器,可实现javaweb程序的装载,是配置JSP和java系统必备的一款环境 Tomcat目 ...
- 线索二叉树C++实现
#include<iostream> #include<stdlib.h> #define maxsize 100 using namespace std; typedef s ...
- Pyinstaller 打包程序为可执行文件exe
Pyiinstaller打包 pyinstaller是python的一个第三方模块,使用它可以将pythnon程序打包为可执行文件,实现打包后的程序在没有python环境的机器上也可以运行.pyins ...
- 2019SACC中国系统架构师大会 day1总结
早上:一. 爱奇艺的大数据中台战略: a) 介绍爱奇艺的产业文化.b) 通过大中台,可以进行部分数据的沉淀,用于后续的分析处理等等.. 从数据中台和业务中台,建立一种“苹果园“的生态系统.从原始的长视 ...
- python 读取域名信息
#!/usr/bin/env python # _*_coding:utf-8_*_ import OpenSSL from OpenSSL import crypto from dateutil i ...
- 【转】Android之四大组件、六大布局、五大存储
文章来自:http://blog.csdn.net/shenggaofei/article/details/52450668 一.四大组件: Android四大组件分别为activity.servic ...
- Android 6.0(棉花糖)新特性
1.支持4K显示 Android 6.0本身已经支持4K显示,会通过一定优化形式使4K内容更加清晰. 2. 启动验证 (更完整的应用权限管理) Android 6.0在开机时会自动运行验证代码,检测设 ...
- HDP之HBase性能调优
(官方文档翻译及整理) 一.系统级调优 1.保证充足的RAM 2.64位的操作系统 3.Linux的swappiness设置为0 : sysctl vm.swappiness=10 vim /etc/ ...
- 珠峰-express
##### #### 中间件的作用 #### 自己写的Route方法 #### #### 中间件
- Linux运维---02.制作trove-redis镜像
redis-3.2 镜像制作及验证 镜像制作 1.安装redis yum install redis yum install epl-release yum install python-pip gi ...