答案都对但没分,求大佬帮忙看看
查看原帖
答案都对但没分,求大佬帮忙看看
1078007
yuyuelong楼主2023/10/23 00:03
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstddef>
using namespace std;
int s[100000];
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;
		for(int i=0;i<lc;i++){
			t+=to_string(c[lc-i]);
		}
		string v=to_string(s[f]);
		memset(c,0,sizeof(c));
		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+100000);
	for (int i=0; i < sizeof(s) / sizeof(s[0]); i++) {
		if (s[i] != 0) {
			cout << s[i] << " ";
		}
	}
	for(;f<sizeof(s)/sizeof(s[0]);f++){
		if(s[f]!=0){
			break;
		}
	}
	f=f+1;
	cout << endl;
	string x=to_string(s[f-1]);
	string y=to_string(s[f]);
	cs(x,y);
	return 0;
}

如题,真的一分没有。。。

2023/10/23 00:03
加载中...