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 ...
随机推荐
- urllib 模块 - module urllib
urllib 模块 - urllib module 获取 web 页面, html = urllib.request.urlopen("http://www.zzyzz.top/" ...
- zabbix-mysql迁移分离
io过高,迁移mysql 停掉zabbix 导出数据库的zabbix库 导入到新机器,并启动mysql 1:修改zabbix_server.conf文件里DB相关的地址,用户名和密码. vim /et ...
- 关于Java/Kotlin下载图片,图片打开不能显示问题探究
图片下载其实是个很简单的功能,通过IO流从在线地址获取流,之后将流输出到文件即可完成下载功能,但是,最近我发现某个网站中的图片下载成功,但是打开却是无法打开,这让我迷惑,百度上根本就没有人说清楚 今天 ...
- webpack之打包分析以及prefetching和preloading
打包分析: https://webpack.js.org/guides/code-splitting/#bundle-analysis 性能优化使用缓存是很有限的,现在更多的应该是再编写 ...
- 仅需60秒,使用k3s创建一个多节点K8S集群!
作者: Dawid Ziolkowski丨Container Solution云原生工程师 最近,我一直在Kubernetes上进行各种测试和部署.因此,我不得不一次又一次创建和销毁Kubernete ...
- scanf函数中*修饰符的作用,如:%*d
在scanf函数中,*修饰符可以跳过所在项的输入.如下: #include <stdio.h> int main() { ; printf("请输入:"); scanf ...
- centos7.x中安装SQL Server
本文内容是采集的好几位博主的博文进行的一个整合,内容更为精准和详尽,以下是我参照的几篇博文地址: 微软官方文档:https://docs.microsoft.com/zh-cn/sql/linux/s ...
- Java架构师必看,超详细的架构师知识点分享!
在Java程序员行业中,有不少Java开发人员的理想是成为一名优秀的Java架构师,Java架构师的主要任务不是从事具体的软件程序的编写,而是从事更高层次的开发构架工作.他必须对开发技术非常了解,并且 ...
- yarn-site.xml 配置介绍
yarn-site.xml 配置介绍 yarn.scheduler.minimum-allocation-mb yarn.scheduler.maximum-allocation-mb 说明:单个容器 ...
- NPM 包管理工具详解,使用教程
NPM 包管理工具 1.1 定义:什么是 NPM NPM 全称 Node Package Manager,它是 JavaScript 的包管理工具, 并且是 Node.js 平台的默认包管理工具.通过 ...