PAT(甲级)1005
2015-09-23 16:09
295 查看
1005. Spell It Right (20)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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 <cstdio> #include <cstring> #define SIZE 105 char num[SIZE]; int main(){ int sum=0; char output[30]; scanf("%s",num); char *p=num; while(*p !='\0'){ sum += *p-'0'; p++; } sprintf(output,"%d",sum); int length = strlen(output); int i=1; p =output; while(i<length){ switch (*p){ case '0':{ printf("zero "); break; } case '1':{ printf("one "); break; } case '2':{ printf("two "); break; } case '3':{ printf("three "); break; } case '4':{ printf("four "); break; } case '5':{ printf("five "); break; } case '6':{ printf("six "); break; } case '7':{ printf("seven "); break; } case '8':{ printf("eight "); break; } case '9':{ printf("nine "); break; } } p++; i++; } switch (*p){ case '0':{ printf("zero\n"); break; } case '1':{ printf("one\n"); break; } case '2':{ printf("two\n"); break; } case '3':{ printf("three\n"); break; } case '4':{ printf("four\n"); break; } case '5':{ printf("five\n"); break; } case '6':{ printf("six\n"); break; } case '7':{ printf("seven\n"); break; } case '8':{ printf("eight\n"); break; } case '9':{ printf("nine\n"); break; } } return 0; }
相关文章推荐
- Android SDK 源码关联
- MySQL 常用命令
- 文献综述格式及写作技巧
- JavaBean使用示例
- 【leetcode】No.150 Evaluate Reverse Polish Notation
- linux编译调用动态库
- 多线程基本概念
- 装饰器模式
- 【斜率DP】BZOJ 3675:[Apio2014]序列分割
- XE2 泛型练习1
- 在AD的环境下,更改计算机名导致TFS,无法连接解决办法
- Linux——waitpid方法
- JavaScript闭包
- 设置一个临时变量交换两个变量的值
- transient:修饰符的使用
- 基于Lookup的IOC事件总线框架
- spring中bean的scope
- 通过反射绕过编译向泛型为String的ArrayList里面添加整型
- 所有前缀在串中出现的次数之和 kmp hdu 3336 count the string
- $()和${}和$(())和(())