1005. Spell It Right (20)
2014-01-29 17:13
288 查看
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:
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 using namespace std; int main(){ string output[] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; string n; cin>>n; char temp; int sum = 0; for(int i=0;i<n.length();i++){ temp = n.at(i); sum+=(temp-48); } int end[100]; int flag=0; if(sum==0){ cout<<output[0]; }else{ while(sum!=0){ end[flag++]=sum%10; sum=sum/10; } for(int i=flag-1;i>0;i--){ cout<<output[end[i]]<<" "; } cout<<output[end[0]]; } return 0; }
相关文章推荐
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT-A 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)
- PAT(甲级)1005. Spell It Right (20)
- PAT (Advanced) 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 (Advanced Level) Practise
- PAT (Advanced Level) Practise 1005 Spell It Right (20)
- PAT 1005. Spell It Right(20)