PAT (Advanced Level) Practise
来源:互联网 发布:mac白屏很久 编辑:程序博客网 时间:2024/04/30 10:14
1005. Spell It Right (20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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:12345Sample Output:
one five
把每位上的数加起来,变成单个英文输出。
#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>#include <math.h>#include <map>using namespace std;const int maxn = 100100;#define LL long longint main(){ char s[111]; scanf("%s",s); int now=0; int len=strlen(s); for(int i=0;i<len;i++){ now+=s[i]-'0'; } if(now==0){ printf("zero\n"); return 0; } int num[111]; int cnt=0; while(now){ num[++cnt]=now%10; now/=10; } map<int,string> mp; mp[0]="zero"; mp[1]="one"; mp[2]="two"; mp[3]="three"; mp[4]="four"; mp[5]="five"; mp[6]="six"; mp[7]="seven"; mp[8]="eight"; mp[9]="nine"; for(int i=cnt;i>=1;i--){ if(i!=cnt) printf(" "); cout<<mp[num[i]]; }}
阅读全文
0 0
- [PAT] (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1005
- pat (advanced level ) Practise 1065
- PAT (Advanced Level) Practise 1070
- PAT (Advanced Level) Practise 1035
- PAT (Advanced Level) Practise 1031
- PAT (Advanced Level) Practise 1015
- PAT (Advanced Level) Practise 1120
- PAT (Advanced Level) Practise 1036
- Tomcat7.0.42源码研读之组件说明(四)
- JAVA设计模式之单例模式
- python the method of super function
- C语言中#、##和do{}while(0)的高效用法
- Vue.JS实战:简单的购物车
- PAT (Advanced Level) Practise
- 文章标题
- Java并发编程:synchronized
- C语言-动态链表的创建遍历与插入
- 八皇后问题(回溯)
- Python系统编程(多线程-互斥锁-死锁-thread-threading)
- 4.3
- PAT (Advanced Level) Practise
- MyBatis之级联