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 很简单的题,最开始错了两次,N最大是10得100次方,用整形存储肯定不够,用字符串存储后就过了
#include <iostream>
#include <string>
#include <map> using namespace std; map<char,string> m;
int result[]; int main()
{
m[]="zero";
m[]="one";
m[]="two";
m[]="three";
m[]="four";
m[]="five";
m[]="six";
m[]="seven";
m[]="eight";
m[]="nine";
string n;
long int sum=;
cin>>n;
int b,i=;
while(n[i]!='\0'){
b=n[i]-;
sum=sum+b;
i++;
}
int x,countnum=;
while(sum){
x=sum%;
result[countnum]=x;
countnum++;
sum=sum/;
}
cout<<m[result[countnum-]];
for(int i=countnum-;i>=;i--){
cout<<" "<<m[result[i]];
} return ;
}
1005. Spell It Right (20)的更多相关文章
- 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 ...
- PAT 甲级 1005. Spell It Right (20) 【字符串】
题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...
- PAT (Advanced Level) 1005. Spell It Right (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <alg ...
随机推荐
- APP开发流程
1.申请一个开发者账号: 2. App的idea形成: 3. App的主要功能设计: 4. App的大概界面构思和设计(使用流程设计): 5. 大功能模块代码编写: 6. 大概的界面模块编写: 7. ...
- 关于在linux中使用图形界面的网络管理工具
有好几种自动设置的工具可以选择(既然说是自动设置的工具,那就说明有手动设置的工具,例如 使用 ip, iw, iwconfig 这些命令设置网络),例如:Connman, netctl, Networ ...
- Yii2中多表关联查询(join、joinwith)
我们用实例来说明这一部分 表结构 现在有客户表.订单表.图书表.作者表, 客户表Customer (id customer_name) 订单表Order (id order_name ...
- Samba快速配置
Samba是linux,unix,windows之间进行交互操作的软件组件,Sanma是基于GPL协议的自由开源软件. 快速配置samba文件服务器 1.关闭防火墙和SELinux [root@cen ...
- EditPlus 3.7.1186 中文版(10月27日更新)重大性能改进,推荐更新!
3.7.* 版的 EditPlus 存在性能问题:加载行数比较多的文档时,要等很长的时间.加载一个十几兆的文本文件,可能需要等十几秒.在编辑窗口内翻页也会有明显的迟滞感.而此前的 3.6 版本并非如此 ...
- Mysql的基础使用之SQL原生语句的使用:表的 创建 删除 修改 (一)
上一篇主要讲的是关于Mysql的分支MariaDB在Linux下的安装 顺利安装完成的小伙伴,就可以接着来试试SQL的魅力了 红色为命令 蓝色为自定义名 查看数据库 MariaDB [(none)]& ...
- java 线程 障碍器
package de.bvb; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.TimeUnit; /** ...
- <基督教福音视频>
<信耶稣还是罪人吗?>全集 http://www.youku.com/playlist_show/id_18458615.html <因信称义>全集 http://www.yo ...
- AB窗体互传参数
一.找了好几个,都不靠谱,不是说不靠谱,自己感觉太繁琐 二.父窗口传子窗口好传,有两种方法(自己认为比较简单的方法哈), 1第一种方法:在子窗口中新建一个属性:再新建一个方法,当然方法就是把属性个窗体 ...
- Paxos算法与Zookeeper分析
1 Paxos算法 1.1 基本定义 算法中的参与者主要分为三个角色,同时每个参与者又可兼领多个角色: ⑴proposer 提出提案,提案信息包括提案编号和提议的value; ⑵acceptor 收到 ...