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

[PAT]1005. Spell It Right (20)

/************************************************************** 1005. Spell It Right (20) 时间限制 400 ...
  • fnzsjt
  • fnzsjt
  • 2014年11月10日 13:35
  • 773

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

PAT A1005 Spell It Right

//解答和我想的是一样的,要注意是二维数组的map即可 //输出change的那里一开始写成了%c,警示! //第一次提交,有一个3分的点错误 //第二次提交,除了0那个测试点其他全部错误,发现把...

浙大 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_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】1005 Spell It Right

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1005 分析:简单题。将输入的字符串一个个的转换成数字再相加,然后将相加的结果用英文打印出来就可以。...

1005. Spell It Right 解析

感觉没什么好说的。我是偷懒用String读入,然后转换计算。代码看上去比较麻烦。 附上AC代码: #include #include #include using namespace st...

浙江大学PAT_甲级_1005.1005. Spell It Right (20)

c++实现
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:1005. Spell It Right (20)
举报原因:
原因补充:

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