1005. Spell It Right (20)
2017-04-26 18:10
309 查看
PAT
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
输入一串字符,加和后用英文输出每一位
代码
#include<cstdio> #include<cstring> using namespace std; int main() { char c[10][20]={"zero","one","two","three", "four","five","six","seven","eight","nine"}; char a[100],b[100]; scanf("%s",a); int sum=0; for(int i=0;i<strlen(a);i++)//加和 sum+=a[i]-'0'; sprintf(b,"%d",sum);//字符串和整型互换 printf("%s",c[b[0]-'0']);//输出第一位 for(int i=1;i<strlen(b);i++) printf(" %s",c[b[i]-'0']); return 0; }
相关文章推荐
- [PAT]1005. Spell It Right (20)@Java
- 【PAT甲级】【C++】1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT-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)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT-A-1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- 1005. Spell It Right (20)
- [PAT甲级]1005. Spell It Right (20)(求数字各个位上的和,英文输出)
- PAT1005. Spell It Right (20)