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. ...
随机推荐
- HttpSession的关键属性和方法
1.当一个用户向服务器发送第一个请求时,服务器为其建立一个session,并为此session创建一个标识号:2.这个用户随后的所有请求都应包括这个标识号.服务器会校对这个标识号以判断请求属于哪个se ...
- 常见jsp跳转总结
这次做项目,用到几种不同的JSP跳转的方式,在此总结5中常用方法. 常用的跳转方式有以下几种: (1)href超链接标记,属于客户端跳转 (2)使用javascript完成,属于客户端跳转 (3)提交 ...
- 根据条件决定是否为input设置只读属性
代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
- Django1.8:403错误:CSRF verification failed. Request aborted.
问题:Django 403错误:CSRF verification failed. Request aborted. 原因:需要加cookie验证 解决方法: 1.在view.py中增加 fr ...
- War(最短路+最大流)
War http://acm.hdu.edu.cn/showproblem.php?pid=3599 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 表单数据转换成json格式数据
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- CentOS7下部署NTP Server
系统环境:CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64 软件版本:chrony-3.1-2.el7.centos.x86_64 ...
- POJ2585 Window Pains 拓扑排序
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1843 Accepted: 919 Descr ...
- 深入浅出 JMS(三) - ActiveMQ 安全机制
深入浅出 JMS(三) - ActiveMQ 安全机制 一.认证 认证(Authentication):验证某个实体或者用户是否有权限访问受保护资源. MQ 提供两种插件用于权限认证: (一).Sim ...
- sd卡不能格式化
可能是读卡器坏了,还真遇到过,花了一下午,各种尝试,最后发现只是读卡器坏了.