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 ...
随机推荐
- PostgreSQL 磁盘使用大小监控
表大小信息 postgres=# SELECT *, pg_size_pretty(total_bytes) AS totalpostgres-# , pg_size_pretty(index_byt ...
- android stduio 引入 .so
- 在nginx日志的access log中记录post请求的参数值
背景:有时程序偶出现参数少了或没有提交到下一个链接Url里后出现问题,如何查呢,最好的办法是在nginx上的加post参数,以定位到问题才有可能对某个UIR的代码出现的问题进行排查. og_forma ...
- Android隐藏状态栏、导航栏
Android隐藏状态栏.导航栏 private void hideStatusNavigationBar(){ if(Build.VERSION.SDK_INT<16){ this.getWi ...
- 诚信的cpm广告联盟该怎么选择
诚信的cpm广告联盟该怎么选择?58传媒广告联盟介绍说,在目前我国的互联网行业发展中,新站长在不断的崛起,这也就意味着老站长在不断的衰败,而老站长的衰败并不是一天两天造成的,而是其长期积累形成的,将错 ...
- c#-快速排序-算法
快速排序使用分治法(Divide and conquer)策略来把一个串行(list)分为两个子串行(sub-lists). 步骤为: 1.从数列中挑出一个元素,称为 "基准"(p ...
- [Android] 修改ImageView的图片颜色
有两种方法: 方法1: ImageView imageView = (ImageView) findViewById(R.id.arrow_image); Drawable tipsArrow = i ...
- python中的argparse模块学习
该模块是python用于解析命令行和参数的标准模块 好文推荐:http://blog.ixxoo.me/argparse.html,不仅域名个性,文章翻译的也很好.推荐
- easyUI+springMVC的DataGrid-demo
DataGrid (一).搭建springMVC: 错误:无法访问HTML页面,HTTP Status 404- 原因:springMVC拦截了静态资源的访问 解决方案:方案①:(web.xml下)& ...
- Entity Framework7 有哪些不同?现在开发到什么程度了?
Entity Framework7之开篇 一.Entity Framework7 简介 Entity Framework7简称EF7,是微软正在开发的最新的在.NET应用中首选的数据访问技术.它是轻量 ...