第七个测试点WA,为什么????
查看原帖
第七个测试点WA,为什么????
482255
Erythrina楼主2021/9/10 19:58
#include<iostream>
#include <cstring>
using namespace std;

int main()
{
	int a[10090], b[10090];
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	string str1, str2;
	cin >> str1 >> str2;
	int judge;
	if (str1 < str2 && str1.size() == str2.size() || str1.size() < str2.size())
	{
		judge = 0;
	}
	else if (str1 == str2)
	{
		judge = 2;
	}
	else {
		judge = 1;
	}
	a[0] = str1.length();
	b[0] = str2.length();
	for (int i = 1; i <= a[0]; i++)
	{
		a[i] = str1[a[0] - i] - '0';
	}
	for (int j = 1; j <= b[0]; j++)
	{
		b[j] = str2[b[0] - j] - '0';
	}
	if (judge == 2)
	{
		cout << 0 << endl;
	}
	else if (judge == 1)
	{
		for (int i = 1; i <= b[0]; i++)
		{
			if (a[i] - b[i] >= 0)
			{
				a[i] = a[i] - b[i];
			}
			else {
				a[i] = a[i] - b[i] + 10;
				a[i + 1]--;
			}
		}
		int u;
		for (int i = a[0]; i > 0; i--)
		{
			if (a[i] != 0)
			{
				u = i;
				break;
			}
		}
		for (int i = u; i > 0; i--)
		{
			cout << a[i];
		}
		cout << endl;
	}
	else {
		cout << "-";
		for (int i = 1; i <= a[0]; i++)
		{
			if (b[i] - a[i] >= 0)
			{
				b[i] = b[i] - a[i];
			}
			else {
				b[i] = b[i] - a[i] + 10;
				b[i + 1]--;
			}
		}
		int u;
		for (int i = b[0]; i > 0; i--)
		{
			if (b[i] != 0)
			{
				u = i;
				break;
			}
		}
		for (int i = u; i > 0; i--)
		{
			cout << b[i];
		}
		cout << endl;
	}
	return 0;
}
...
2021/9/10 19:58
加载中...