只有50分,求大佬指正
查看原帖
只有50分,求大佬指正
481792
nbge楼主2021/3/6 16:55
#include<iostream>

using namespace std;

int jc(int n, int* v);
int plusin(int* c, int n2, int* v, int n1);
void output(int* v, int n);

int main()
{
	int n, n1 = 1, n2;
	int v[1000], c[1000];
	v[0] = 1;
	cin >> n;
	for (int i = 2; i <= n; i++)
	{
		n2 = jc(i, c);
		n1 = plusin(c, n2, v, n1);
	}
	output(v, n1);
	return 0;
}

int jc(int n, int* v)
{
	int n1=1, jw = 0;
	v[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < n1; j++)
		{
			int y = v[j] * i + jw;
			v[j] = y % 10;
			jw = y / 10;
		}
		if (jw > 0)
		{			
			v[n1] = jw;
			n1++;
		}
		jw = 0;
	}
	return n1;
}

int plusin(int* c, int n2, int* v, int n1)
{
	int jw = 0;
	for (int i = 0; i < n1 && i < n2; i++)
	{
		int y = v[i] + c[i] + jw;
		v[i] = y % 10;
		jw = y / 10;
	}
	if (n1 > n2)
	{
		for (int j = n2; j < n1; j++)
		{
			int x = v[j] + jw;
			v[j] = x % 10;
			jw = x / 10;
		}
		if (jw > 0)
		{
			v[n1] = jw;
			n1++;
		}
	}
	if (n2 > n1)
	{
		for (int j = n1; j < n2; j++)
		{
			int x = c[j] + jw;
			v[j] = x % 10;
			jw = x / 10;
		}
		if (jw > 0)
		{
			v[n2] = jw;
			n2++;
		}
		n1 = n2;
	}
	return n1;
}
void output(int* v, int n)
{
	for (int i = n - 1; i >= 0; i--)
	{
		cout << v[i];
	}
}
2021/3/6 16:55
加载中...