PAT1005Spell It Right (20)
2016-05-10 10:19
549 查看
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
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
string num; cin >> num; string book[10] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; int len = num.length(), sum = 0; for (int i = 0; i < len; ++i){ sum += (num[i] - '0'); } vector<int> tmp; while (sum > 0){ tmp.push_back(sum % 10); sum = sum / 10; } len = tmp.size(); for (int i = len - 1; i >= 0; --i){ cout << book[tmp[i]] << " "; }
相关文章推荐
- shape 动态颜色设置
- [Java视频笔记]day20
- iOS7 edgesForExtendedLayout
- iOS quartzCore第五章——CAShapeLayer画各种图形 结合UIBezierPath
- 图片预加载与懒加载
- POJ 2367 Genealogical tree (拓扑排序)
- IntelliJ idea 中使用Git
- 详解数据库设计准则: 第一范式,第二范式,第三范式
- Setting Up MySQL Debugging Environment
- Spark开发指南
- 8.2 使用 MySQL 数据库
- 别再抱怨了,国内这么多优秀的Android资源你都知道吗?
- 20160510 GreenPlum4 SQL中求和相关语句的总结
- [javase]IO之InputStream
- css样式优先级详解
- Linux内核配置
- POI2015 题解
- 博客从“新浪云“迁移到CSDN的说明
- dedecms自定义表单
- Python核心编程(第九章)--文件和输入输出