#include <cstring> #include <cstdio> struct node { char a[2005]; int b[2005]; int len; void reverse() { for(int i=0;i<len;++i) b[len-i+1]=a[i]-‘0‘; } bool operator - (node m)const { for(int i=1;i<=len;++i) { if(b[i]<0) b[i+1]=b[i+1]-b[i],b[i]=b[i]+(-b[i]); for(;b[i]<m.b[i];b[i]++,b[i+1]--); b[i]=b[i]-m.b[i]; } } bool operator<(node m)const { if(len!=m.len) return len>m.len; else { for(int i=0;i<len;++i) if(a[i]!=m.a[i]) return a[i]>m.a[i]; } } }aa,bb,cc; int main() { scanf("%s%s",aa.a,bb.a); aa.len=strlen(aa.a); bb.len=strlen(bb.a); aa.reverse(); bb.reverse(); if(aa.a>bb.a) aa-bb; else { puts("-"); bb-aa; } puts(cc.a); return 0; }
时间: 2024-10-07 06:08:51