您的位置:首页 > 其它

高精度——高精度减法

2017-02-10 20:13 281 查看
P2142 高精度减法

题目描述

高精度减法

分析

高精度减法

var
s1,s2,s:ansistring;
a,b,c:array[0..100000]of longint;
i:longint;
begin
readln(s1);
readln(s2);
a[0]:=length(s1);
b[0]:=length(s2);
if (a[0]<b[0])or((a[0]=b[0])and(s1<s2)) then
begin
s:=s1;s1:=s2;s2:=s;write('-');
end;
a[0]:=length(s1);
b[0]:=length(s2);
for i:=a[0] downto 1 do val(s1[i],a[a[0]-i+1]);
for i:=b[0] downto 1 do val(s2[i],b[b[0]-i+1]);
for i:=1 to a[0] do
begin
c[i]:=a[i]-b[i]+c[i];
if c[i]<0 then
begin
dec(c[i+1]);
c[i]:=c[i]+10;
end;
end;
for i:=length(s1) downto 2 do if c[i]=0 then dec(a[0]) else break;
for i:=a[0] downto 1 do write(c[i]);
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: