锤叔日记
2024-07-12 14:23:48
发布于:福建
9阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
string s1,s2;
int a[2500000],b[2500000],c[2500000];
int len,p;
int main(){
cin >> s1 >> s2;
if(s1.size() < s2.size() || s1.size()==s2.size()&& s1<s2){
cout << "-";
swap(s1,s2);
}
for(int i = 0; i < s1.size(); i++){ //逆序
a[s1.size()-1-i] =s1[i]-'0';
}
for(int i = 0; i < s2.size(); i++){ //逆序
b[s2.size()-1-i] =s2[i]-'0';
}
len = s1.size();
if(len < s2.size()){
len = s2.size();
}
for(int i = 0; i < len; i++){
c[i] = a[i] - b[i];
}
for(int i = 0; i < len; i++){
if(c[i]< 0){
c[i+1] = c[i+1] - 1;
c[i] += 10;
}
}
for(int i = len - 1; i >= 0; i--){
if(c[i] != 0){
p = i;
break;
}
}
for(int i = p; i >=0; i--){
cout << c[i];
}
return 0;
}
这里空空如也
有帮助,赞一个