编译失败求解
查看原帖
编译失败求解
1491219
user_888楼主2025/1/20 21:05
#include <iostream>
using namespace std;
#include<string>
#include<algorithm>
const int l = 100;
int a_arr[l], b_arr[l];
int c_arr[l], d_arr[l];
int n;
void cin_in_arr(string s, int a[]) {
	int j = 0;
	for (int i = s.size() - 1;i >= 0;i--)a[j++] = s[i]-48;
}

void print_arr(int a[], int len) {
	for (int i = 0;i < len;i++)cout << a[i] << ' ';
}

string mymultiply(string a, string b) {
	if (a == "0" || b == "0")return "0";
	int arr[l] = { 0 };
	cin_in_arr(a, a_arr);
	cin_in_arr(b, b_arr);

	for (int i = 0;i < a.size();i++) 
		for (int j = 0;j < b.size();j++) 
			arr[i + j] += a_arr[i] * b_arr[j];
	//进位
	for (int i = 0;i < a.size() + b.size();i++) {
		arr[i + 1] += arr[i] / 10;
		arr[i] = arr[i] % 10;
	}
	//print_arr(arr, 100);
	string res = "";
	bool flag = false;
	for (int i = a.size() + b.size();i >= 0;i--) {
		if (arr[i] != 0||flag) {
			flag =true;
			res += to_string(arr[i]);
		}
	}
	return res;
}

string myplus(string a, string b) {
	if (a == "0" && b == "0")return "0";
	int res[l] = { 0 };
	cin_in_arr(a, c_arr);
	cin_in_arr(b, d_arr);
	//print_arr(c_arr, 10);
	int j = 0;
	for (int i = 0;i < max(a.size(), b.size());i++) {
		res[j++] = c_arr[i] + d_arr[i];
	}
	//进位
	for (int i = 0;i < a.size() + b.size()+5;i++) {
		res[i + 1] += res[i] / 10;
		res[i] = res[i] % 10;
	}
	//print_arr(res, 10);
	string c_res = "";
	bool flag = false;
	for (int i = max(a.size(), b.size());i >= 0;i--) {
		if (res[i] != 0 || flag) {
			c_res += to_string(res[i]);
			flag = true;
		}
	}
	return c_res;
}

int main()
{
	cin >> n;
	string res = "0";
	string jie = "1";
	for (int i = 1;i <= n;i++) {
		jie = mymultiply(to_string(i), jie);
		res = myplus(jie, res);
		memset(a_arr, 0, sizeof(a_arr));
		memset(b_arr, 0, sizeof(b_arr));
		memset(c_arr, 0, sizeof(c_arr));
		memset(d_arr, 0, sizeof(d_arr));
	}
	cout << res;

//	system("pause");

	return 0;
}
2025/1/20 21:05
加载中...