PAT (Advanced Level) Practise - 1005. Spell It Right (20)
2017-11-04 22:40
537 查看
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:
12345
Sample 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 long
int 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]];
}
}
相关文章推荐
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT-PAT (Advanced Level) Practise 1005. Spell It Right (20) (简单模拟题)【一星级】
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- 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,哈希
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005 Spell It Right
- PAT(Advanced Level)1005. Spell It Right (20) 栈 int转string
- 【PAT (Advanced Level)】1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20)
- 【PAT Advanced Level】1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20) 解题报告
- PAT (Advanced) 1005. Spell It Right (20)
- PAT Advanced 1005. Spell It Right (20) (C语言实现)
- [PAT (Advanced Level) ]1005. Spell It Right解题文档
- Pat(Advanced Level)Practice--1005(Spell It Right)