PAT 1005 Spell It Right (20)(字符转换)
2016-09-01 10:19
435 查看
题目
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
AC代码
#include<iostream> #include<sstream> #include<string> #include<stack> using namespace std; string in2str[] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; int main(int argc, char *argv[]) { string a; cin >> a; if (a=="0") { cout << "zero" <<endl; return 0; } int len = a.length(); long long sum = 0; for (int i = 0; i < len; ++i) { //cout << a[i] - '0' <<endl; sum += a[i] - '0'; } stack<string> keep; while (sum>0) { keep.push(in2str[sum%10]); sum = sum / 10; } string top = keep.top(); cout << top; keep.pop(); while (!keep.empty()) { top = keep.top(); keep.pop(); cout << " " << top; } cout << endl; //cout << sum << endl; return 0; }
相关文章推荐
- [PAT]1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- PAT: 1005. Spell It Right (20)
- [PAT]1005. Spell It Right (20)
- 【PAT (Advanced Level)】1005. Spell It Right (20)
- 【PAT甲级】【C++】1005. Spell It Right (20)
- PAT 甲 1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- PAT - 甲级 - 1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT(甲级)1005. Spell It Right (20)
- 【PAT Advanced Level】1005. Spell It Right (20)
- PAT-PAT (Advanced Level) Practise 1005. Spell It Right (20) (简单模拟题)【一星级】
- PAT1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20)
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- PAT---1005. Spell It Right (20)
- (PAT)1005. Spell It Right (20)