提交时间:2023-10-07 13:05:19

运行 ID: 105511

#include<bits/stdc++.h> using namespace std; string a1,b1; int a[5005]={0},b[5005]={0},s[5005],lena,lenb,lens,flag=0; int main() { cin>>a1>>b1; if(a1.length()<b1.length()||a1.length()==b1.length()&&a1<b1) { string t; t=a1; a1=b1; b1=t; cout<<'-'; } lena=a1.length(); lenb=b1.length(); lens=max(lena,lenb); for(int i=1;i<=lena;i++) a[i]=a1[lena-i]-48; for(int i=1;i<=lenb;i++) b[i]=b1[lenb-i]-48; for(int i=1;i<=lens;i++) { if(a[i]<b[i]) { a[i+1]--; a[i]+=10; } s[i]=a[i]-b[i]; } while(!s[lens]&&lens>1) lens--; for(int i=lens;i>=1;i--) cout<<s[i]; return 0; }