1005. Spell It Right (20)
2014-09-08 20:15
423 查看
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:
[/code]
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> using namespace std; void make(int a) { if(a==0) cout<<"zero"; if(a==1) cout<<"one"; if(a==2) cout<<"two"; if(a==3) cout<<"three"; if(a==4) cout<<"four"; if(a==5) cout<<"five"; if(a==6) cout<<"six"; if(a==7) cout<<"seven"; if(a==8) cout<<"eight"; if(a==9) cout<<"nine"; } int main() { string str; int n=0; cin>>str; for(int i=0;i<str.length();i++) n+=str[i]-'0'; //cout<<n<<endl; int m[4]={0}; if(n==0) cout<<"zero"; for(int i=0;i<4;i++) { m[i]=n%10; n/=10; } for(int i=3;i>=0;i--) { if(m[i]!=0) { make(m[i]); for(int j=i-1;j>=0;j--) { cout<<" "; make(m[j]); } break; } } return 0; }
[/code]
相关文章推荐
- 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)
- 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 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)
- PAT(甲级)1005. Spell It Right (20)
- PAT (Advanced) 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- PAT(甲级)1005. Spell It Right (20)