O(n)高精减,如果第二个大于第一个要输出负号。var a,b,c:array[0..1000] of longint; x,y,z:ansistring; i,j,k,l:longint; t:boolean;begin readln(x); readln(y); if x=y then begin writeln(0);exit;end; l:=length(x); k:=length(y); t:=true; if (k>l)or(k=l)and(y>x) then begin t:=false; z:=x;x:=y;y:=z; j:=l;l:=k;k:=j; end; for i:=1 to l do val(x[l-i+1],a[i]); for i:=1 to k do val(y[k-i+1],b[i]); for i:=1 to l do begin c[i]:=c[i]+a[i]-b[i]; if c[i]<0 then begin c[i]:=c[i]+10; dec(c[i+1]); end; end; while c[l]=0 do dec(l); if not t then write('-'); for i:=l downto 1 do write(c[i]);end.