提交时间:2025-08-04 10:26:44
运行 ID: 337608
#include<bits/stdc++.h> using namespace std; string a,b; int x,y,cnt[250],cnt1[250],l,sum[250]; void d(){ for(int i=0;i<l;i++){ if(cnt[i]<cnt1[i]){ cnt1[i]--; cnt[i]++; } sum[i]=cnt[i]-cnt1[i]; } while(l!=0&&sum[l]==0) l--; return; } bool c(string s1,string s2){ if(x>y) return 0; if(x<y) return 1; for(int i=0;i<l;i++){ if(s1[i]<s2[i]) return 1; if(s1[i]>s2[i]) return 0; } return 0; } int main(){ cin>>a>>b; x=a.size(); y=b.size(); for(int i=0;i<x;i++){ cnt[i]=a[x-1-i]-'0'; } for(int i=0;i<y;i++){ cnt1[i]=b[y-1-i]-'0'; } l=max(x,y); d(); if(c(a,b)){ cout<<"-"; swap(a,b); swap(x,y); } for(int i=l;i>=0;i--){ cout<<sum[i]; } return 0; }