作业帮 > 综合 > 作业

1.求两个正整数(不超过一百位)的和.2.求两个正整数(不超过一百位)的差.用Free pascal

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/05/15 00:50:32
1.求两个正整数(不超过一百位)的和.2.求两个正整数(不超过一百位)的差.用Free pascal
1.求两个正整数(不超过一百位)的和.2.求两个正整数(不超过一百位)的差.用Free pascal
这两道题都是高精度运算
在这里我给你我的第一题代码 (不超过254位,string最长254,可以用ansistring增加长度)
var a,b,c:string;r,i,h,f,e:integer;
begin
readln(a);
readln(b);
f:=length(a);
e:=length(b);
for i:=1 to abs(f-e) do c:=c+'0';
if f>e then b:=c+b
else a:=c+a;
c:='';
for i:=length(a) downto 1 do
begin
h:=ord(a[i])+ord(b[i])+r-96;
r:=h div 10;
c:=chr(h mod 10+48)+c;
end;
if r>0 then c:='1'+c;
writeln(c);
end.
通过 100分
测试点1: 答案正确 340KB 4MS
测试点2: 答案正确 336KB 4MS
测试点3: 答案正确 340KB 0MS
测试点4: 答案正确 336KB 0MS
测试点5: 答案正确 340KB 0MS
测试点6: 答案正确 336KB 0MS
测试点7: 答案正确 336KB 0MS
测试点8: 答案正确 336KB 0MS
测试点9: 答案正确 336KB 4MS
测试点10: 答案正确 336KB 4MS
手打党! BS抄袭!
LS那个程序就不说了吧.
第二题 楼主可以改下第一题的程序 自己动手试试吧 .呵呵