40分WA求调
查看原帖
40分WA求调
685939
1214__qwq楼主2022/6/19 20:59
#include <iostream>
#include <string>
using namespace std;

int A[1010], B[1010], sum[1010];

void s2BIG(string s, int a[])
{
	int la = s.length();
	for(int i = 1; i <= la; i++)
		a[i] = s[la - i] - '0';
	a[0] = la;
}

void i2BIG(int n, int a[])
{
	int la = 0;
	while(n > 0)
	{
		a[++la] = n % 10;
		n /= 10;
	}
	if(la == 0)
		la++;
	a[0] = la;
}

void addBIG(int x[], int y[],
int z[])
{
	z[0] = max(x[0], y[0]);
	for(int i = 1; i <= z[0]; i++)
		z[i] = x[i] + y[i];
	for(int i = 1; i <= z[0]; i++)
	{
		z[i + 1] += z[i] / 10;
		z[i] %= 10;
		if(z[z[0] + 1] > 0)
			z[0]++;
	}
}

void printBIG(int a[])
{
	int la = a[0];
	for(int i = la; i >= 1; i--)
		cout << a[i];
	cout << endl;
}

int main()
{
	string x;
	int y;
	cin >> x >> y;
	s2BIG(x, A);
	i2BIG(y, B);
	addBIG(A, B, sum);
	printBIG(sum);
	return 0;
}

自己弄了几组比较小的数据(大概long long以内吧)测试了一下都是对的,问题出在哪里了

2022/6/19 20:59
加载中...