前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PAT 1005 Spell It Right

PAT 1005 Spell It Right

作者头像
ShenduCC
发布2018-04-26 17:32:12
5860
发布2018-04-26 17:32:12
举报
文章被收录于专栏:算法修养算法修养

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:

代码语言:javascript
复制
12345

Sample Output:

one five

代码语言:javascript
复制
#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;

}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-05-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1005. Spell It Right (20)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档