PAT 1005
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
简单的模拟类型题,没什么好说的。
代码
1 #include <stdio.h>
2 #include <string.h>
3
4 int main()
5 {
6 char str[];
7 char* const_str[] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
8 while(gets(str)){
9 int n = strlen(str);
int i = ;
int sum = ;
for (;i<n;++i){
sum = sum + str[i] - '';
}
sprintf(str,"%d",sum);
n = strlen(str);
printf("%s",const_str[str[]-'']);
for(i=;i<n;++i){
printf(" %s",const_str[str[i]-'']);
}
printf("\n");
}
return ;
}
PAT 1005的更多相关文章
- PAT——1005. 继续(3n+1)猜想
pat原题目:https://www.patest.cn/contests/pat-b-practise/1005 原题目: 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况 ...
- PAT 1005 Spell It Right
1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all ...
- PAT 1005 继续(3n+1)猜想 (25)(代码)
1005 继续(3n+1)猜想 (25)(25 分) 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下 ...
- PAT 1005. 继续(3n+1)猜想 (25) JAVA
当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进行验证的时候,我们需要计算3.5.8.4.2.1,则当我们对n=5.8.4.2进行验证的时候,就可以直接 ...
- PAT 1005. 继续(3n+1)猜想 (25)
卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进行验证的时候, ...
- PAT——1005. 继续(3n+1)猜想 (25)
卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进行验证的时候, ...
- PAT 1005 继续(3n+1)猜想
https://pintia.cn/problem-sets/994805260223102976/problems/994805320306507776 卡拉兹(Callatz)猜想已经在1001中 ...
- PAT 1005 Spell It Right 字符串处理
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...
- PAT 乙级 1005
题目 题目地址:PAT 乙级 1005 题解 本题主要就在于将一个数的一系列计算结果不重复地存储起来并便于检索,考虑到STL中的集合有相似的特性,使用set可以有效地简化代码和运算. 过程如下: (初 ...
随机推荐
- 【转】10分钟搭建NDK的Android开发环境
原文网址:http://blog.csdn.net/u012176591/article/details/23018913 作者:金良(golden1314521@gmail.com) csdn博客: ...
- jQuery.Validate验证库
一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.4.5
Suppose it is known that $\scrM$ is an invariant subspace for $A$. What invariant subspaces for $A\o ...
- Kafka Unknow host
今天在测试kafka时遇到 Unknow host问题,经过Google,找到了解决办法,总结如下: 原因:Linux主机名称为null 第一步通过修改/etc/sysconfig/network 中 ...
- MVC 实现计算页面执行时间
使用 ActionFilterAttribute 来实现: public class PerformanceActionAttribute:ActionFilterAttribute { public ...
- bzoj 3124 [Sdoi2013]直径(dfs)
Description 小Q最近学习了一些图论知识.根据课本,有如下定义.树:无回路且连通的无向图,每条边都有正整数的权值来表示其长度.如果一棵树有N个节点,可以证明其有且仅有N-1 条边. 路径:一 ...
- 【暑假】[深入动态规划]UVa 10618 The Bookcase
UVa 12099 The Bookcase 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42067 思路: ...
- codeforce 609A - USB Flash Drives
排序水题 #include<iostream> #include<cstdlib> #include<cstdio> #include<algorithm&g ...
- windows7开启虚拟wifi和虚拟无线AP的方法
你可以开启windows 7的隐藏功能:虚拟WiFi和SoftAP(即虚拟无线AP),就可以让电脑变成无线路由器,实现共享上网. 1.点开始 所有程序 命令提示符右键管理员身份运行命令 ...
- C语言简短程序gcc编译过程
一.建立一个×.c源文件.这里起名:rocks.c 二.编辑源代码,在c源文件内输入如下代码: #include <stdio.h> int main() { puts("C R ...