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 ...
随机推荐
- Spring整合EasyExcel【基础设计】
前言 Java解析.生成Excel比较有名的框架有Apache poi.jxl.但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI ...
- Shell脚本 小程序演示
一般的shell编程 场景贯穿了几个熟知的步骤: ●显示消息●获取用户输入●存储值到文件●处理存储的数据 这里写一个小程序 包含以上几部 #!/bin/bash while true do #echo ...
- Linux设备中的UUID
UUID简介 UUID为系统中的存储设备提供唯一的标识字符串,不管这个设备是什么类型的.如果你在系统中启动的时候,使用盘符挂载时,可能找不到设备而加载失败,而使用UUID挂载时,则不会有这样的问题.( ...
- [PowerShell]Windows服务开启、重启、关闭
# 获取服务信息 PS C:\Users\Administrator> Get-Service win* Status Name DisplayName ------ ---- -------- ...
- STT-MRAM万能存储器芯片
传统存储器的技术局限以及不断缩小的制造尺寸所带来的巨大挑战促使科研人员开始寻找新一代存储器件,它应具有接近静态存储器的纳秒级读写速度,具有动态存储器甚至闪存级别的集成密度和类似Flash的非易失性存储 ...
- App自动化测试环境搭建
只做记录和注意点,详细内容不做解释 环境:win+appium+夜神模拟器+python 需要用到的工具: 1.java JDK 2. node.js 3. Android SDK 4.Appium- ...
- 在pycharm中如何设置代码对齐竖线
方法:启动pycharm软件,打开一个文件,点 file 菜单,选择 settings,在弹出的setting菜单中依次选择editor-->general-->appearance,然后 ...
- Centos7.6 Mysql数据库自动备份配置
1.查看磁盘空间情况 执行 df -h 选择剩余空间最大的目录 (以/目录为例) 2.创建备份目录: cd / mkdir backup cd backup 3.创建备份Shell脚本: vim mo ...
- JS隐藏显示图片
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- vue基于video.js实现视频播放暂停---切图网
切图网是最早致力于PSD2HTML切图等web前端外包服务的,随着前端技术的更新迭代,现在也已经全面投入了vue的浪潮了,下面是vue中实现视频播放的方法. vue.js中引入video视频播放器 m ...