PAT 1005 Spell It Right
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<bits/stdc++.h>
using namespace std;
typedef long long ll; vector<string> vec={{"zero"},{"one"},{"two"},{"three"},{"four"},{"five"},{"six"},{"seven"},{"eight"},{"nine"}}; vector<int> temp; int main(){
string s;
cin >> s;
ll sum = ;
for(int i=;i < s.size();i++){
sum += (s[i]-'');
}
if(sum == ) cout << vec[];
while(sum){
temp.push_back(sum%);
sum = sum/;
}
for(int i=temp.size()-;i>=;i--){
cout << vec[temp[i]];
if(i) cout << " ";
} return ;
}
sum = 0的情况要注意,不会进入循环。
PAT 1005 Spell It Right的更多相关文章
- PAT 1005 Spell It Right 字符串处理
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) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- PAT 甲级 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 th ...
- 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【字符串】
1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...
- 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 ...
- PAT 1005
1005. Spell It Right (20) Given a non-negative integer N, your task is to compute the sum of all the ...
- 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 th ...
- 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 ...
随机推荐
- (转载)西门子PLC学习笔记十五-(数据块及数据访问方式)
一.数据块 数据块是在S7 CPU的存储器中定义的,用户可以定义多了数据块,但是CPU对数据块数量及数据总量是有限制的. 数据块与临时数据不同,当逻辑块执行结束或数据块关闭,数据块中的数据是会保留住的 ...
- (转载)用C#实现MySQL建库及建表
最近做一个项目,为了方便用户使用,希望可以在系统初始化的时候,自动实现MySQL数据库的建库和建表操作.在网上查了很多资料都没有找到合适的,偶尔在一个国外网站上看到了相关的内容,特把实现方法整理如下: ...
- Images之管理image
Manage images The easiest way to make your images available for use by others inside or outside your ...
- 【译】第39节---EF6-数据库命令日志
原文:http://www.entityframeworktutorial.net/entityframework6/database-command-logging.aspx 本节,我们学习如何记录 ...
- leecode第三十三题(搜索旋转排序数组)
class Solution { public: int search(vector<int>& nums, int target) { int len=nums.size(); ...
- angular7 + d3 显示svg
汇总一些之前没有注意到的问题 总体思路: app只是显示svg为主,接收后端推送的数据改变,显示变化后的svg. 因此,只用d3的数据绑定更新组件里<svg></svg>节点. ...
- spring cloud: zuul(五): prefix访问前缀, ignoredServices粗粒度访问, yml不起作用
路由的前缀 - 问题 zuul.prefix: 我们可以指定一个全局的前缀 strip-prefix: 是否将这个代理前缀去掉 zuul: prefix: /ecom 我的eureka:http:// ...
- 创建型模式之Builder(建造者)模式
GitHub地址:https://github.com/zhangboqing/design-mode/tree/master/src/main/java/com/zbq 一.定义 建造者模式 ...
- LeetCode--007--整数反转(java)
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出 ...
- 20170814xlVBA限定日期按客户分类汇总
原始数据表: 汇总格式: Sub subtotalDic() Dim Wb As Workbook Dim Sht As Worksheet Dim oSht As Worksheet Dim mYe ...