1005. Spell It Right (20)
来源:互联网 发布:柴庆丰事件知乎 编辑:程序博客网 时间:2024/06/06 16:42
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<iostream> #include<string>#include<sstream>using namespace std;string cc[10] = { "zero", "one", "two","three","four","five","six","seven","eight","nine" };void print(char ch, bool b){ int c = ch - '0'; if (b) cout << cc[c]; else cout << cc[c] << " " << flush;}int main(){ string s; int s_int = 0; cin >> s; for (int i = 0; i < s.size(); ++i) { s_int += s[i] - '0'; } stringstream ss; ss << s_int; string result; ss >> result; for (int i = 0; i < result.size(); ++i) { if (i == result.size() - 1) print(result[i], true); else print(result[i], false); } return 0;}
0 0
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- Linux文件类型和目录结构+Shell的使用
- 图像分割之区域生长
- Linux C:利用两个线程实现生产者消费者模型
- c++中的单继承,多继承(此处着重讲菱形继承)的内存布局模型详解
- 一种求解线性方程组的技巧
- 1005. Spell It Right (20)
- 6.1 android 之持久化技术
- Java利用反射机制分析类的能力
- 416D Population Size
- python网络爬虫(二)
- poj 4006 Genghis Khan the Conqueror <最小生成树 + dfs + 插入>
- 卡诺图学习笔记
- axis
- ubuntu下CMake学习