语法问题求助
查看原帖
语法问题求助
1078007
yuyuelong楼主2023/10/22 22:59
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstddef>
using namespace std;
int s[10000000];
char s1[505], s2[505];
int a[505], b[505], c[505];
int f=1;
void pl(int n) {
	int x = 0;
	if (n % 2 != 0) {
		while (s[x] != 0) {
			x++;
		}
		s[x] = n / 2 + 1;
		s[x + 1] = n / 2;
		return;
	}
	else {
		s[x] = n / 2;
		pl(n / 2);
	}
}
void cs(string x,string y) {
	size_t la, lb, lc;
	la = x.size();
	lb = y.size();
	for (int i = 0; i < la; i++) {
		a[la - i] = x[i] - '0';
	}
	for (int i = 0; i < lb; i++) {
		b[lb - i] = y[i] - '0';
	}
	lc = la + lb;
	for (int i = 1; i <= la; i++) {
		for (int j = 1; j <= lb; j++) {
			c[i + j - 1] += a[i] * b[j];
		}
	}
	for (int i = 1; i < la + lb; i++) {
		if (c[i] > 9) {
			c[i + 1] += c[i] / 10;
			c[i] %= 10;
		}
	}
	while (c[lc] == 0 && lc != 1) {
		lc--;
	}
	f += 1;
	if (s[f]!=0) {
		string t[505];
		for(int i=0;i<lc;i++){
			t[i]=to_string(c[i+1]);
		}
		string v=to_string(s[f]);
		cs(t,v);
	}
	else {
		for (size_t i = lc; i > 0; i--) {
			cout << c[i];
		}
	}
}
int main() {
	int n; 
	memset(s, 0, sizeof(s));
	cin >> n;
	pl(n);
	sort(s,s+10000000);
	for (int i=0; i < sizeof(s) / sizeof(s[0]); i++) {
		if (s[i] != 0) {
			cout << s[i] << " ";
		}
	}
	cout << endl;
	string x=to_string(s[0]);
	string y=to_string(s[1]);
	cs(x,y);
	return 0;
}

能请大佬帮我看看这个第58行代码该怎么改吗?就是cs(t,v)那里,v一直报错,查了各种资料都没解释,请大佬不吝赐教

2023/10/22 22:59
加载中...