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

PAT 1005

作者头像
week
发布2018-08-27 10:06:36
2460
发布2018-08-27 10:06:36
举报
文章被收录于专栏:用户画像用户画像

1005. Spell It Right (20)

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:

代码语言:javascript
复制
one five
代码语言:javascript
复制
#include <iostream>
#include <stack>
#include <string.h>
using namespace std;
#define max 100
char input[max];
int main()
{
	stack<int> s;
	int i,t,len,sum=0;
    cin>>input;
	len=strlen(input);
	for(i=0;i<len;i++)
	{
		t=input[i]-'0';
		sum+=t;
	}
	while(sum/10!=0)//sum>10
	{
		t=sum%10;//个位
		sum=sum/10;
		s.push(t);//入栈
	}
	s.push(sum);
	while(!s.empty()){
		t=s.top();
		s.pop();
		if(t==1)
		{
			cout<<"one";
		}
		if(t==2)
		{
			cout<<"two";
		}
		if(t==3)
		{
			cout<<"three";
		}
		if(t==4)
		{
			cout<<"four";
		}
		if(t==5)
		{
			cout<<"five";
		}
		if(t==6)
		{
			cout<<"six";
		}
		if(t==7)
		{
			cout<<"seven";
		}
		if(t==8)
		{
			cout<<"eight";
		}
		if(t==9)
		{
			cout<<"nine";
		}
		if(t==0)
		{
			cout<<"zero";
		}
		if(!s.empty()){
			cout<<" ";
		}else{
			cout<<endl;
		}
		
	}
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年02月28日,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

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