pat1005. Spell It Right (20)
1005. Spell It Right (20)
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 (<= 10100).
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 <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
string digits[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main(){
string ss;
int sum=,i=,csum=;
cin>>ss;
while(i<ss.length()){
sum+=ss[i++]-'';
}
if(!sum){
cout<<digits[sum]<<endl;
return ;
}
stack<string> s;
while(sum){
s.push(digits[sum%]);
sum/=;
}
cout<<s.top();
s.pop();
while(!s.empty()){
cout<<" "<<s.top();
s.pop();
}
return ;
}
pat1005. Spell It Right (20)的更多相关文章
- PAT---1005. Spell It Right (20)
#include<iostream> #include<stack> #include<string.h> ]= {"zero", " ...
- PAT 甲级 1005 Spell It Right (20)(代码)
1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...
- PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏
1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PTA 1005 Spell It Right (20)(20 分)水题
1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...
- 1005 Spell It Right (20分)
1005 Spell It Right (20分) 题目: Given a non-negative integer N, your task is to compute the sum of all ...
- 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 ...
- 1005 Spell It Right (20)(20 point(s))
problem Given a non-negative integer N, your task is to compute the sum of all the digits of N, and ...
- 1005. Spell It Right (20)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...
- PAT (Advanced Level) 1005. Spell It Right (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- C#中线程的委托
很多时候写windows程序都需要结合多线程,在C#中用如下得代码来创建并启动一个新的线程. Thread thread = new Thread(new ThreadStart(ThreadProc ...
- 转载:ResultMap和ResultType在使用中的区别
在使用mybatis进行数据库连接操作时对于SQL语句返回结果的处理通常有两种方式,一种就是resultType另一种就是resultMap,下面说下我对这两者的认识和理解 resultType:当使 ...
- LoadRunner--获取请求的返回结果函数
注:内容来自网络 Action(){ web_set_max_html_param_len("262144"); // 默认最大长度为256 web_reg_save_param( ...
- [Swift实际操作]九、完整实例-(1)在iTunesConnect网站中创建产品
本文将通过一个实例项目,演示移动应用开发的所有步骤.首先要做的是打开浏览器,并进入[iTunesConnect网站],需要通过它创建一款自己的应用. 在iTunesConnect的登录页面中,输入自己 ...
- python连接postgreSQL
利用python(我用的是python2.7版本)连接postgresql数据库,这里使用psycopg2这个插件 官网下载psycopg2-2.5.1.tar.gz:http://initd.org ...
- Python3之shutil模块
一. 简介 shutil 是高级的文件,文件夹,压缩包处理模块. 二. 使用 shutil.copyfileobj(fsrc, fdst[, length])将文件内容拷贝到另一个文件中 import ...
- 190411Python面向对象编程
一.面向对象的概念 类:把一类事物的相同特征抽取出来整合到一起就是一个类,类是一个抽象的概念 对象:基于类创建的一个具体的事物 class People(object): '这是一个人类的类' def ...
- win8.1 开启企业模式
1,Win+R Gpedit.msc 2, 3, 4,F12 多了一项企业模式
- (C/C++) Link List - C++ 版本
利用C++寫一個基本的 Link list 練習,功能包含 pint list.CreatList.Insert.Delete.Reverse.Search.Clear.GetLen. 先建立相關的C ...
- NAND NOR Flash 和MTD
来自:http://blog.sina.com.cn/s/blog_6b489d5e0102xm62.html 一.NAND和NOR Flash 一般来说,快闪记忆体可分为两大规格,一个是NAND, ...