Pat(Advanced Level)Practice--1005(Spell It Right)
2014-02-09 22:40
369 查看
Pat1005代码
题目描述: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
AC代码:
#include<cstdio> #include<cstring> #define MAX 110 using namespace std; int main(int argc,char *argv[]) { int i,j,len; int sum=0,index; int stack[MAX]; char str[MAX]; char mode[10][10]={"zero","one","two","three","four", "five","six","seven","eight","nine"}; scanf("%s",str); len=strlen(str); for(i=0;i<len;i++) sum=sum+(str[i]-'0'); j=0; while(sum) { stack[j++]=sum%10; sum=sum/10; } index=stack[--j]; printf("%s",mode[index]); --j; for(;j>=0;j--) { index=stack[j]; printf(" %s",mode[index]); } printf("\n"); return 0; }
相关文章推荐
- PAT (Advanced Level) 1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20)
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- PAT Advanced Level 1005:Spell It Right
- PAT(Advanced Level)1005. Spell It Right (20) 栈 int转string
- PAT (Advanced Level) Practise - 1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT-PAT (Advanced Level) Practise 1005. Spell It Right (20) (简单模拟题)【一星级】
- 【PAT】【Advanced Level】1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20) string转int,哈希
- 【PAT (Advanced Level)】1005. Spell It Right (20)
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1005 Spell It Right
- 【PAT Advanced Level】1005. Spell It Right (20)
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- PAT (Advanced Level) 1005. Spell It Right (20) 解题报告
- [PAT (Advanced Level) ]1005. Spell It Right解题文档
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT(Advanced Level) 1005 - Spell It Right (水题)
- PAT (Advanced Level) Practise 1005 Spell It Right (20)