为啥老是提示re?菜菜眼瞎真的找不到
查看原帖
为啥老是提示re?菜菜眼瞎真的找不到
1380473
ZY_202301005129楼主2024/7/6 15:32
#include<iostream>
#include<string>
using namespace std;
#define N 5002
int a[N], b[N];
void sub(int a[], int x, int y)
{
	if (a[x] - y < 0)
	{
		a[x] = a[x] - y + 10;
		sub(a, x + 1, 1);
	}
	else
	{
		a[x] -= y;
	}
}
int main()
{
	string a1, b1;
	cin >> a1 >> b1;
	if (a1 == b1)
	{
		cout << 0;
		return 0;
	}
	for (int i = 1;i <= a1.size();i++)
		a[i] = a1[a1.size() - i]-48;
	for (int i = 1;i <= b1.size();i++)
		b[i] = b1[b1.size() - i]-48;
	if (a1.size()>b1.size()||(a1.size() == b1.size()&&a1.compare(b1)>0))
	{
		for (int i = 1;i <= b1.size();i++)
			sub(a, i, b[i]);
		int i = a1.size();
		while (a[i] == 0)i--;
		while (i > 0)cout << a[i--];
	}
	else
	{
		for (int i = 1;i <= a1.size();i++)
			sub(b, i, a[i]);
		int i = b1.size();
		while (b[i] == 0)i--;
		cout << "-";
		while (i > 0)cout << b[i--];
	}
}
2024/7/6 15:32
加载中...