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:
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 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]];    }}



原创粉丝点击