PAT 1005 Spell It Right

来源:互联网 发布:mac high sierra好吗 编辑:程序博客网 时间:2024/04/28 10:17

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 <string.h>#include <stdlib.h>#include <stdio.h>#include <algorithm>#include <math.h>#include <queue>#include <map>#include <strstream>#include <string>using namespace std;char a[105];map<int,string> m;int main(){  m[0]="zero";  m[1]="one";  m[2]="two";  m[3]="three";  m[4]="four";  m[5]="five";  m[6]="six";  m[7]="seven";  m[8]="eight";  m[9]="nine";  scanf("%s",a);  int num=0;  int len=strlen(a);  for(int i=0;i<len;i++)    num+=(a[i]-'0');  string s;  strstream ss;  ss << num;  ss >> s;  int len2=s.length();  for(int i=0;i<len2;i++)  {    if(i==len2-1)      cout<<m[s[i]-'0']<<endl;    else        cout<<m[s[i]-'0']<<" ";  }  return 0;}


0 0
原创粉丝点击