- 高精度乘法
- 2013-11-14 13:00:30 @
pascal解法
program gaojingdujiafa;
var
a,b,c:array[1..10000] of longint;
n:ansistring;
la,lb,lc,i,x,j:longint;
begin
readln(n);
la:=length(n);
for i:=1 to la do a[la-i+1]:=ord(n[i])-ord('0');
readln(n);
lb:=length(n);
for i:=1 to lb do b[lb-i+1]:=ord(n[i])-ord('0');
x:=0;
i:=1;
for i:=1 to la do
begin
x:=0;
for j:=1 to lb do
begin
c[i+j-1]:=a[i]*b[j]+c[i+j-1];
x:=c[i+j-1] div 10;
c[i+j-1]:=c[i+j-1] mod 10
end;
c[i+j]:=x;
end;
lc:=la+lb;
while (c[lc]=0) and (lc>1) do lc:=lc-1;
for i:=lc downto 1 do write(c[i]);
end.
2 条评论
-
xiangshang12 LV 8 @ 2014-08-25 16:28:38
RP问题
-
2013-11-14 13:01:04@
第三个数据**runtime error**
- 1