求助,90分
查看原帖
求助,90分
1242208
wyp20130701_是一个蒟蒻楼主2025/8/4 08:57
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string strmax(string A, string B){
	if (A.length() != B.length()){
		if (A.length() > B.length()) return A;
		else return B;
	}
	for (int i = A.length() - 1; i >= 0; i--){
		if (A[i] > B[i]) return A;
		else if (A[i] < B[i]) return B;
	}
}
int a[10090], b[10090];
int main(){
	string A, B;
	cin >> A >> B;
	bool fu = false;
	if (strmax(A, B) == B){
		fu = true;
		swap(A, B);
	}
	for (int i = A.length() - 1; i >= 0; i--) a[A.length() - i] = A[i] - '0';
	for (int i = B.length() - 1; i >= 0; i--) b[B.length() - i] = B[i] - '0';
	int len = A.length();
	for (int i = 1; i <= len; i++){
		if (a[i] < b[i]){
			a[i + 1]--;
			a[i] += 10;
		}
		a[i] -= b[i];
	}
	while (!a[len]) len--;
    if (fu) cout << '-';
	for (int i = max(1, len); i >= 1; i--) cout << a[i];
	return 0;
}

在线等,急

2025/8/4 08:57
加载中...