1005. Spell It Right (20)

原创 2015年11月21日 19:27:17

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<cstdio>
#include<cstring>
#include<stack>
using namespace std;

const char digit[10][6] = {"zero","one","two","three","four","five","six","seven","eight","nine"};

stack<int> result;
char input[102];

int main(void)
{
	scanf("%s",input);
	int sum = 0;
	int length = strlen(input);
	for(int i = 0;i<length;++i)
	{
		sum+=input[i] - '0';
	}
	do
	{
		result.push(sum%10);
		sum /= 10;
	}while(sum>0);
	do
	{
		printf("%s",digit[result.top()]);
		result.pop();
		if(!result.empty())
			printf(" ");
	}while(!result.empty());
	
//	system("pause");
	return 0;
}


版权声明:本文为jungleni原创文章,转载请注明出处。

相关文章推荐

1005. Spell It Right (20)

http://www.patest.cn/contests/pat-a-practise/1005 Given a non-negative integer N, your task...

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 e...

[PAT]1005. Spell It Right (20)

/************************************************************** 1005. Spell It Right (20) 时间限制 400 ...

PAT1005. Spell It Right (20)

1005. Spell It Right (20)时间限制400 ms 内存限制65536 kB 代码长度限制16000 B 判题程序Standard作者CHEN, Yue Given a non-n...

【PAT (Advanced Level)】1005. Spell It Right (20)

1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B...

PAT1005. Spell It Right (20)

题目如下: Given a non-negative integer N, your task is to compute the sum of all the digits of N, a...

1005. Spell It Right (20)

这个题简单,就直接贴在这吧,注意一点输入数据规模比较大,要用char来存储 Given a non-negative integer N, your task is to compu...

1005. Spell It Right (20)

1005. Spell It Right (20)

浙大 PAT Advanced level 1005. Spell It Right

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e...

PAT A1005 Spell It Right

//解答和我想的是一样的,要注意是二维数组的map即可 //输出change的那里一开始写成了%c,警示! //第一次提交,有一个3分的点错误 //第二次提交,除了0那个测试点其他全部错误,发现把...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)