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 ...
随机推荐
- mpt_voronoi demo
% %demo1% A=rand(3,10);% pbound=Polyhedron([0 0 0;150 0 0;150 150 0;0 150 0; 0 0 1;150 0 1;150 150 1 ...
- Hihocoder 1063 缩地
树形dp 涉及不重复背包组合求最小 从边长分段看不好入手 因为点数只有100点值<=2,总值<=200 可以对每个点的每个值进行dp 这里最后不回来肯定优于全回来 然后由于要分为回来和不回 ...
- Tomcat使用,部署
Tomcat服务器基本使用 web服务软件,也叫web服务器软件,web服务器. 基本使用 1)下载 到apache官网下载. http://www.apache.org 安装版本:window e ...
- jmeter安装配置教程
1.下载Jmeter 下载地址:http://jmeter.apache.org/download_jmeter.cgi 目前最新版为3.1,其余文件如源代码等也可从如下官网下载: http://jm ...
- 面试 JavaWeb 部分
1.Tomcat的优化经验 答:去掉对web.xml的监视,把jsp提前编辑成Servlet. 有富余物理内存的情况,加大tomcat使用的jvm的内存 2.HTTP请求的GET与POST方式的区别 ...
- 彻底卸载Oracle
彻底卸载Oracle 用Oracle自带的卸载程序不能从根本上卸载Oracle,从而为下次的安装留下隐患,那么怎么才能完全卸载Oracle呢?那就是直接注册表清除,步骤如下: 1. 开始->设置 ...
- Mysql 常用 SQL 语句集锦 转载(https://gold.xitu.io/post/584e7b298d6d81005456eb53)
Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...
- nodejs cookie管理
Cookie 管理 我们可以使用中间件向 Node.js 服务器发送 cookie 信息,以下代码输出了客户端发送的 cookie 信息: // express_cookie.js 文件 var ex ...
- 增加VirtualBox虚拟机的磁盘空间大小(Host:Win7 VirtualBox5.0.16 VM:Win10)
1 前言 网上关于增加VirtualBox虚拟机的磁盘空间大小的文章非常非常多,这里我之所以再写一篇,是因为在参照这些文章做的时候,由于VirtualBox的版本更新以及其他一些环境问题,碰到到一些问 ...
- java第二次作业
这次通过学习,我掌握了下拉菜单和单选按钮的使用下拉菜单构造方法:JComboBox() 创建具有默认数据模型的 JComboBox.JComboBox(ComboBoxModel aModel) 创建 ...