# 高精减

132人阅读 评论(0)

var
s,sa,sb:string;
a,b:array[1..max] of integer;
len,la,lb, i:integer;
fh:char;
begin
if sa=sb then begin writeln(0);halt;end;
if (length(sa)<length(sb))or
((length(sa)=length(sb))and(sa<sb)) then
begin fh:='-'; s:=sa; sa:=sb; sb:=s; end;

la:=length(sa); lb:=length(sb);
fillchar(a,sizeof(a),0);  fillchar(b,sizeof(b),0);
for i:= la downto 1 do a[la-i+1]:=ord(sa[i])-ord('0');
for i:= lb downto 1 do b[lb-i+1]:=ord(sb[i])-ord('0');
len:=la;
for i:=1 to len do
begin
if a[i]<b[i] then
begin
a[i+1]:=a[i+1]-1;
a[i]:=a[i]+10;
end;
a[i]:=a[i]-b[i];
end;
while a[len]=0 do len:=len-1;
if fh='-' then write(fh);
for i:=len downto 1 do write(a[i]);
writeln;
end.

size= 200;
type
hugeint = record
len : integer;
num : array[1..size] Of Integer;
end;
var a,b:hugeint;
s1,s2:string;
i:integer;
function over(a, b : hugeint) : integer;
var
i : Integer;
begin
If (a.len>b.len) then
begin
over :=1 ;
exit;
end;
if a.len < b.len then
begin
over := 2;
exit;
end;
for i := a.len downto 1 do
begin
If a.num[i] > b.num[i] then
begin
over := 1;
exit;
end;
if a.num[i] < b.num[i] then
begin
over := 2;
exit;
end;
end;
over := 3;
end;
procedure minus(a,b:hugeint);
var
i:longint;
t,ans:hugeint;
begin
fillchar(ans.num,sizeof(ans.num),0);
if over(a,b)=2 then
begin
write('-');
t:=a;a:=b;b:=t;
end;
if over(a,b)=3 then begin writeln(0);exit;end;
ans.len:=a.len;
for i:=1 to ans.len do ans.num[i]:=a.num[i]-b.num[i];
for i:=1 to ans.len do
if ans.num[i]<0 then
begin
dec(ans.num[i+1]);
inc(ans.num[i],10);
end;
while (ans.len>1)and(ans.num[ans.len]=0) do dec(ans.len);
for i:=ans.len downto 1 do write(ans.num[i]);
writeln;
end;
procedure datain;
begin
//assign(input,'highminus.in');  assign(output,'highminus.out');
//reset(input); rewrite(output);
a.len:=length(s1);
b.len:=length(s2);
for i:=1 to a.len do  a.num[i]:=ord(s1[a.len-i+1])-ord('0');
for i:=1 to b.len do  b.num[i]:=ord(s2[b.len-i+1])-ord('0');
end;
begin
datain;
minus(a,b);
//close(input);close(output);
end.

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：15180次
• 积分：108
• 等级：
• 排名：千里之外
• 原创：91篇
• 转载：0篇
• 译文：0篇
• 评论：0条
文章分类
文章存档
阅读排行
评论排行