PAT:A1005. Spell It Right (20/20)
2017-02-08 21:52
567 查看
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
#include <cstdio>#include <cstring>char n[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};int main(){char num[110];gets(num);int len=strlen(num);int sum=0;for(int i=0;i<len;i++){sum+=num[i]-'0';}int i=0;int digit[1000];do{digit[i++]=sum%10;sum/=10;}while(sum);for(--i;i>=0;i--){printf("%s",n[digit[i]]);if(i>0)printf(" ");}return 0;}
相关文章推荐
- libdvbpsi源码分析(四)PAT表解析/重建
- PAT配置
- 什么是端口复用动态地址转换(PAT) 介绍配置实例
- MikroTik layer7-protocol
- PAT是如何工作的
- PAT 乙级题:1002. 写出这个数 (20)
- PAT (Advanced Level) Practise 1001-1010
- PAT (Basic Level) Practise (中文)
- 数据结构学习与实验指导(一)
- PAT Basic Level 1001-1010解题报告
- PAT 数素数
- PAT 福尔摩斯的约会
- PAT 德才论
- PAT 月饼
- 1001. 害死人不偿命的(3n+1)猜想
- 1002. 写出这个数
- 1032. 挖掘机技术哪家强
- 1001. 害死人不偿命的(3n+1)猜想 (PAT basic)
- 1002. 写出这个数(PAT Basic)
- 1004. 成绩排名(PAT Basic)