1005. Spell It Right (20)
2017-06-19 10:36
267 查看
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:
计算数字各个位数的总和,然后输出总和每位数字的英文
。。。。。。。。。。。。。。。。。。改了半天才发现是four拼错了
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
char s1[12][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int sum=0;
char str[10000];
cin>>str;
for(int i=0;i<strlen(str);i++)
sum+=str[i]-'0';
int a[1000],cnt=0;
while(sum){
a[cnt++]=sum%10;
sum/=10;
}
cout<<s1[a[cnt-1]];
for(int i=cnt-2;i>=0;i--) cout<<" "<<s1[a[i]];
return 0;
}
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
计算数字各个位数的总和,然后输出总和每位数字的英文
。。。。。。。。。。。。。。。。。。改了半天才发现是four拼错了
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
char s1[12][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int sum=0;
char str[10000];
cin>>str;
for(int i=0;i<strlen(str);i++)
sum+=str[i]-'0';
int a[1000],cnt=0;
while(sum){
a[cnt++]=sum%10;
sum/=10;
}
cout<<s1[a[cnt-1]];
for(int i=cnt-2;i>=0;i--) cout<<" "<<s1[a[i]];
return 0;
}
相关文章推荐
- PAT1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- 【PAT甲级】1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT (Advanced Level) 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)
- 1005.Spell It Right (20)
- 1005. Spell It Right (20)
- PAT 甲 1005. Spell It Right (20)
- 1005. Spell It Right (20)