PAT A 1005. Spell It Right (20)
2017-02-20 20:31
453 查看
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:
12345Sample Output:
one five
// 题目分析:
字符串数组存储字符串常量
// 代码
#include <iostream> #include <string> #include <vector> using namespace std; int main(){ char a[110]; string strs[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; scanf("%s",a); int i=0; int sum=0; while(a[i]!='\0'){ sum+=a[i]-'0'; i++; } vector<int> v; while(sum!=0){ v.push_back(sum%10); sum/=10; } for(int i=v.size()-1;i>0;i--){ cout<<strs[v[i]]<<' '; } if(v.empty()){ cout<<"zero"; }else{ cout<<strs[v[0]]; } system("pause"); return 0; }
//结果
相关文章推荐
- PAT A 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- [PAT]1005. Spell It Right (20)
- PAT TEST 甲级1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 【PAT Advanced Level】1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT-A 1005. Spell It Right (20)
- PAT甲级.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)
- 1005 Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
- PAT (Advanced) 1005. Spell It Right (20)