PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏
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<stdio.h>
#include<string.h>
int main()
{
char s[1000];
int t[1000],sum,u[1000],i,j,k,n;
while(scanf("%s",s)!=EOF)
{
k=strlen(s);
sum=0;
for(i=0;i<k;i++)
{
t[i]=s[i]-'0';
sum+=t[i];
}
if(sum==0)
printf("zero\n");
else
{
j=0; while(sum!=0)
{
u[j++]=sum%10;
sum/=10;
}
n=0;
for(i=j-1;i>=0;i--)
{
while(n++)
{
printf(" ");
break;
}
if(u[i]==0)
printf("zero");
else if(u[i]==1)
printf("one");
else if(u[i]==2)
printf("two");
else if(u[i]==3)
printf("three");
else if(u[i]==4)
printf("four");
else if(u[i]==5)
printf("five");
else if(u[i]==6)
printf("six");
else if(u[i]==7)
printf("seven");
else if(u[i]==8)
printf("eight");
else if(u[i]==9)
printf("nine");
}
printf("\n");
}
}
return 0;
}
PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏的更多相关文章
- PAT甲 1006. Sign In and Sign Out (25) 2016-09-09 22:55 43人阅读 评论(0) 收藏
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- hdu3333 Turing Tree 2016-09-18 20:53 42人阅读 评论(0) 收藏
Turing Tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏
1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...
- PAT甲 1007. Maximum Subsequence Sum (25) 2016-09-09 22:56 41人阅读 评论(0) 收藏
1007. Maximum Subsequence Sum (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...
- House Robber 分类: leetcode 算法 2015-07-09 20:53 2人阅读 评论(0) 收藏
DP 对于第i个状态(房子),有两种选择:偷(rob).不偷(not rob) 递推公式为: f(i)=max⎧⎩⎨⎪⎪{f(i−1)+vali,f(i−2)+vali,robi−1==0robi−1 ...
- ZOJ2417 Lowest Bit 2017-04-18 20:53 38人阅读 评论(0) 收藏
Lowest Bit Time Limit: 2 Seconds Memory Limit: 65536 KB Given an positive integer A (1 <= A ...
- 如何在hadoop中控制map的个数 分类: A1_HADOOP 2015-03-13 20:53 86人阅读 评论(0) 收藏
hadooop提供了一个设置map个数的参数mapred.map.tasks,我们可以通过这个参数来控制map的个数.但是通过这种方式设置map的个数,并不是每次都有效的.原因是mapred.map. ...
随机推荐
- python中时间差中seconds和total_seconds
在python中经常会用到计算两个时间差,两个日期类型进行相减可以获取到时间差 经常会使用seconds来获取,其实seconds获取的是时间差的秒数,遗漏了天 seconds是获取时间部分的差值,而 ...
- java包 命名规范 [转]
Java的包名都有小写单词组成,类名首字母大写:包的路径符合所开发的 系统模块的 定义,比如生产对生产,物资对物资,基础类对基础类.以便看了包名就明白是哪个模块,从而直接到对应包里找相应的实现. 由于 ...
- 求数组中的逆序对的数量----剑指offer36题
在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数: 如数组{7,5,6,4},逆序对总共有5对,{7,5},{7,6},{7, ...
- XML与HTML
一.什么是HTML 带着疑问走到这里,一句话:HTML(HyperTextMark-upLanguage)即超文本标记语言,是WWW的描述语言. 如果想了解更多请看以下博客: http://blog. ...
- Redis cli 操作
备份 root@575e8088b5fb:/data# redis-cli LASTSAVE(integer) 1500273743root@575e8088b5fb:/data# redis-cli ...
- Fb 第三方接口
1.Facebook ID? User ID / https://www.piliapp.com/facebook/id/?url=https%3A%2F%2Fwww.facebook.com%2Fz ...
- logging的使用
[logging的使用] import logging # 创建一个logger logger = logging.getLogger('mylogger') logger.setLevel(logg ...
- Alberta family's QR code is world's largest corn maze
BY DARREN WEIR SEP 10, 2012 IN ODD NEWS Link:http://www.digitaljournal.com/article/332512 Laco ...
- 慕课网access_token的获取
access_token的接口是微信公众号一个基础接口,access_token接口微信公众号一个非常重要的接口 access_token是微信公众号的全局唯一票据,公众号的所有接口的调用都需要使用到 ...
- Little-endian和Big-endian(小端数据和大端数据)
Little和Big指的是内存地址的大小,end指的是数据的末尾. Little-endian指内存地址低的地方存数据的末尾(即低字节) Big-endian指内存地址高的地方存数据的末尾(即高字节) ...