大神看一看!!!!那错了!!!!!!!!!!!

P1303 A*B Problem

韦敏 @ 2017-08-21 21:48:12

type gjint=array[1..100000] of longint;
var a,b,c:gjint;i:longint;
procedure du(var a:gjint);
Var s:string; i:integer;
begin
  readln(s);a[0]:=0;
  for i:=length(s) downto 1 do
begin
  inc(a[0]);
  a[a[0]]:=ord(s[i])-ord('0');
 end;
end;
 procedure chen(a,b:gjint; var c:gjint);
 var i,jw,k,l,o,p,t:longint;
 begin
 jw:=0;
 if a[0]>=b[0] then c[0]:=a[0]
    else c[0]:=b[0];
   for i:=1 to c[0] do
   begin
   c[i]:=a[i]*b[i]+jw;
   c[i]:=c[i] mod 10;
   jw:=c[i] mod 10;
  end;
  while jw<>0 do
  begin
  inc(c[0]);
  c[c[0]]:=jw mod 10;
  jw:=jw div 10;
 end;
end;
procedure sc(c:gjint);
var i:longint;
begin
  for i:=c[0] downto 1 do
  write(c[i]);
end;
begin
  du(a);du(b);
  chen(a,b,c);
  sc(c);
end.

那错了 看看


by renyifan010410 @ 2017-08-21 22:45:17

楼主,我眼睛不太好,不能帮你慢慢看,抱歉,(好像是进位那里有问题)附自己的代码一份。

program p1303;
var a,b,c:array[1..10000] of longint;
    s1,s2:ansistring;
    i,j,x,n:longint;
begin
  readln(s1);
  readln(s2);
  if (s1='0') or (s2='0') then begin write(0); halt; end;
  for i:=1 to length(s1) do
    a[length(s1)-i+1]:=ord(s1[i])-ord('0');
  for i:=1 to length(s2) do
    b[length(s2)-i+1]:=ord(s2[i])-ord('0');
  for i:=1 to length(s1) do
  begin
    x:=0;
    for j:=1 to length(s2) do
    begin
      c[i+j-1]:=c[i+j-1]+a[i]*b[j]+x;
      x:=c[i+j-1] div 10;
      c[i+j-1]:=c[i+j-1] mod 10;
    end;
    c[i+j]:=x;
  end;
  n:=i+j;
  if c[i+j]=0 then dec(n);
  for i:=n downto 1 do write(c[i]);
  readln;
  readln;
end.

希望能帮到你


|