1005. Spell It Right (20)
2016-10-29 20:13
417 查看
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
#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; }
相关文章推荐
- 1005. Spell It Right (20)
- PAT A 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT 1005 Spell It Right (20)(字符转换)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT甲级-1005. Spell It Right (20)各位之和
- PAT 1005. Spell It Right (20)
- Python 实现Pat 1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- PAT甲级.1005. Spell It Right (20)
- PAT-A-1005. Spell It Right (20)
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
- 1005. Spell It Right (20) PAT甲级刷题
- [PAT] 1005 Spell It Right (20)
- PAT(甲级)1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20) 解题报告