PAT (Advanced Level) Practise 1005. Spell It Right (20)
来源:互联网 发布:js e.currenttarget 编辑:程序博客网 时间:2024/06/06 01:55
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:12345Sample Output:
one five
题解:
因为对大整数模板比较熟悉,很自然就想到利用大整数模板,然后再数位求和,最终挺快就AC了。所以,有属于自己的算法模板还是比较重要的,写博客的过程其实也是积累的过程。
代码:
#include <cstdio>#include <cstring>char mp[15][7]={"zero","one","two","three","four","five","six","seven","eight","nine"};struct bign{ int d[105]; int len; bign(){ memset(d,0,sizeof(d)); len=0; }};bign change(char s[]){ bign a; a.len=strlen(s); for(int i=0;i<a.len;i++) a.d[i]=s[a.len-1-i]-'0'; return a;}int main(){ char s[105]; gets(s); bign a=change(s); int sum=0; for(int i=0;i<a.len;i++) sum+=a.d[i]; int buf[105],num=0; do{ buf[num++]=sum%10; sum/=10; }while(sum); for(int i=num-1;i>=0;i--){ if(i==num-1) printf("%s",mp[buf[num-1]]); else printf(" %s",mp[buf[i]]); } return 0;}
阅读全文
0 0
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005 Spell It Right (20)
- PAT-PAT (Advanced Level) Practise 1005. Spell It Right (20) (简单模拟题)【一星级】
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1005 Spell It Right
- PAT(Advanced level) 1005. Spell It Right
- 【PAT Advanced Level】1005. Spell It Right (20)
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- 【PAT (Advanced Level)】1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20) 解题报告
- PAT (Advanced Level) 1005. Spell It Right (20)
- 【PAT】【Advanced Level】1005. Spell It Right (20)
- PAT Advanced Level 1005:Spell It Right
- PAT (Advanced) 1005. Spell It Right (20)
- [PAT (Advanced Level) ]1005. Spell It Right解题文档
- 浙大 PAT Advanced level 1005. Spell It Right
- Java ExecutorService四种线程池的例子与说明
- 负载均衡重点业务梳理
- centos 安装 netstat ifconfig
- python去除list中空字符串最快最简单的方法
- Android Studio配置文件路径修改
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- Swift 返回一个渐变的 UIImageView
- Ubuntu开机无法进入系统问题(NVIDIA显卡驱动相关)
- C#网络编程系列文章(三)之TcpListener实现异步TCP服务器
- Ineger的缓存区
- 工作计划量与实际量的对比, 日期时间
- HTML 状态码
- Vmware安装ubuntu编译android源码详细过程
- jsp的执行过程