码迷,mamicode.com
首页 > 编程语言 > 详细

hdu1024 N! (数组模拟乘法过程)

时间:2015-08-06 22:36:18      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:



N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 65655    Accepted Submission(s): 18807


Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
 

Input
One N in one line, process to the end of file.
 

Output
For each N, output N! in one line.
 

Sample Input
1 2 3
 

Sample Output
1 2 6
 

Author
JGShining(极光炫影)
 

Recommend
We have carefully selected several similar problems for you:  1715 1047 1063 1753 1316 
 

Statistic | Submit | Discuss | Note

第一次 想这数组开小点1w把。。其实真不小了。。

可我还是太嫩了。。原来要开到35700。。

#include <stdio.h>
#include <string.h>
using namespace std;
#define N 35700
int main()
{
	int n;
	char num[N];
	while(scanf("%d",&n)!=EOF)
	{
		memset(num,'0',sizeof(num));
		num[0]='1';
		for(int i=2;i<=n;i++)
		{
			int r=0,k;
			for(int j=0;j<N;j++)
			{
				k=(num[j]-'0')*i+r;
				num[j]=k%10+'0';
				r=k/10;
			}
		}
		int i;
		for(i=N-1;i>=0;i--)
		if(num[i]!='0')
		break;
		for(int j=i;j>=0;j--)
		printf("%c",num[j]);
		printf("\n");
	}
	return 0;
}


N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 65655    Accepted Submission(s): 18807


Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
 

Input
One N in one line, process to the end of file.
 

Output
For each N, output N! in one line.
 

Sample Input
1 2 3
 

Sample Output
1 2 6
 

Author
JGShining(极光炫影)
 

Recommend
We have carefully selected several similar problems for you:  1715 1047 1063 1753 1316 
 

Statistic | Submit | Discuss | Note

第一次 想这数组开小点1w把。。其实真不小了。。

可我还是太嫩了。。原来要开到35700。。

#include <stdio.h>
#include <string.h>
using namespace std;
#define N 35700
int main()
{
	int n;
	char num[N];
	while(scanf("%d",&n)!=EOF)
	{
		memset(num,'0',sizeof(num));
		num[0]='1';
		for(int i=2;i<=n;i++)
		{
			int r=0,k;
			for(int j=0;j<N;j++)
			{
				k=(num[j]-'0')*i+r;
				num[j]=k%10+'0';
				r=k/10;
			}
		}
		int i;
		for(i=N-1;i>=0;i--)
		if(num[i]!='0')
		break;
		for(int j=i;j>=0;j--)
		printf("%c",num[j]);
		printf("\n");
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu1024 N! (数组模拟乘法过程)

标签:

原文地址:http://blog.csdn.net/su20145104009/article/details/47322189

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!