求高精度减法的程序
- 提问者网友:刺鸟
- 2021-07-25 03:16
- 五星知识达人网友:千夜
- 2021-07-25 04:10
var a,b:array[1..1000]of shortint;
i,la,lb:integer;
f:boolean;
fin,fout:text;
s:string;
function Bbig:boolean;
var i:integer;
begin
Bbig:=false;
if lb>la then Bbig:=true
else if lb=la then
for i:=la downto 1 do
if b[i]>a[i] then Bbig:=true
else if a[i]>b[i] then exit;
end;
procedure minus;
var t:array[1..1000]of shortint;
begin
if Bbig then begin
t:=a;
a:=b;
b:=t;
write(fin,'-');
end;
for i:=1 to 1000 do begin
a[i]:=a[i]-b[i];
if a[i]<0 then begin
a[i+1]:=a[i+1]-1;
a[i]:=a[i]+10;
end;
end;
end;
begin
for i:=1 to 1000 do begin a[i]:=0; b[i]:=0;end;
readln(fin,s);
la:=length(s);
for i:=1 to length(s) do a[i]:=ord(s[length(s)-i+1])-48;
read(fin,s);
lb:=length(s);
for i:=1 to length(s) do b[i]:=ord(s[length(s)-i+1])-48;
minus;
f:=false;
for i:=1000 downto 1 do begin
if a[i]<>0 then f:=true;
if f then write(fout,a[i]);
end;
end.