题目:
两个500位以内的数字相乘求解。
分析:
做过的,像模拟我们做乘法就行啦。
代码:
const
maxn=1000;
var
a,b,c:array [1..maxn] of longint;
s1,s2:ansistring;
procedure init;
var
i:longint;
begin
readln(s2);
for i:=1 to length(s2) do
if s2[i]=' ' then
begin
s1:=copy(s2,1,i-1);
delete(s2,1,i);
break;
end;
end;
function ggc(s1,s2:ansistring):ansistring;
var
i,j,lena,lenb,lenc,temp:longint;
s:ansistring;
begin
lena:=length(s1);
lenb:=length(s2);
for i:=1 to lena do
a[lena-i+1]:=ord(s1[i])-48;
for i:=1 to lenb do
b[lenb-i+1]:=ord(s2[i])-48;
for i:=1 to lena do
begin
temp:=0;
for j:=1 to lenb do
begin
temp:=a[i]*b[j]+temp div 10+c[i+j-1];
c[i+j-1]:=temp mod 10;
end;
c[i+j]:=temp div 10;
end;
lenc:=i+j;
while (c[lenc]=0) and (lenc>1) do
dec(lenc);
for i:=lenc downto 1 do
begin
str(c[i],s);
ggc:=ggc+s;
end;
end;
begin
init;
write(ggc(s1,s2));
end.