WA~~求救
查看原帖
WA~~求救
1124438
hgfs楼主2024/6/17 10:34
#include<bits/stdc++.h>
using namespace std;

string a,b;

string jian(string a,string b){
	bool d=1;
	string c="";
	if(a.size()<b.size() || (a.size()==b.size() && a[0]<b[0])){
		d=0;
		swap(a,b);
	}
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for(int i=0;i<a.size();i++){
		if(a[i]<b[i]){
			a[i+1]--;
			a[i]+=10;
		}
		if(i>=b.size()) b+='0';
		c+=a[i]-b[i]+'0';
	}
	while(c.size()>1 && c[c.size()-1]=='0') c=c.substr(0,c.size()-1);
	if(!d) c+='-'; 
	reverse(c.begin(),c.end());
	return c;
}

int main(){
	cin>>a>>b;
	cout<<jian(a,b);
	return 0;
}
2024/6/17 10:34
加载中...