|
#include <bits/stdc++.h>
using namespace std;
#define N 205
int a[N];
int b[N];
int c[N];
int ans[N];
int main(){
string a1,b1;
cin>>a1>>b1;
if(((a1.size()==b1.size()) &&(a1<b1)) || (a1.size()<b1.size())){
cout<<"-";
string c1;
c1=a1;
a1=b1;
b1=c1;
}
for(int i=0;i<a1.size();i++) a[a1.size()-i-1]=a1[i]-'0';
for(int i=0;i<b1.size();i++) b[b1.size()-i-1]=b1[i]-'0';
int anslen=max(a1.size(),b1.size());
for(int i=0;i<anslen;i++){
ans[i]=a[i]-b[i]-c[i];
if(ans[i]<0){
c[i+1]=1;
ans[i]+=10;
}
}
int flag=0;
for(int i=anslen-1;i>=0;i--){
if(ans[i]==0 && flag==0) continue;
flag=1;
printf("%d",ans[i]);
}
if(flag==0) cout<<0;
return 0;
}
|
|