求助(60)

P1303 A*B Problem

Henry_he @ 2016-12-09 20:23:22

为何有错

var a,b,c:array[1..100000]of longint;
    s:string;
    i,j,k,x,la,lb:longint;
begin
  readln(s);
  la:=length(s);
  for i:=1 to la do
    a[i]:=ord(s[la-i+1])-ord('0');
  readln(s);
  lb:=length(s);
  for i:=1 to lb do
    b[i]:=ord(s[lb-i+1])-ord('0');
  for i:=1 to la do
  begin
    x:=0;
    for j:=1 to lb 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;
  k:=la+lb;
  while (c[k]=0)and(k>1) do
    dec(k);
  for i:=k downto 1 do
    write(c[i]);
end.

by Henry_he @ 2016-12-27 21:08:35

function chen(s1,s2:ansistring):ansistring;
var   a,b,c:array[1..200] of 0..9;
      lena,lenb,lenc,i,j,x:integer;
begin
  lena:=length(s1);
  lenb:=length(s2);
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),0);
  fillchar(c,sizeof(c),0);
  for i:=1 to lena do
    a[lena-i+1]:=ord(s1[i])-ord('0');
  for i:=1 to lenb do
    b[lenb-i+1]:=ord(s2[i])-ord('0');
  for i:=1 to lena do
  begin
    x:=0;
    for j:=1 to lenb do
     begin
      x := a[i]*b[j]+x div 10+c[i+j-1];
      c[i+j-1]:=x mod 10;
     end;
     c[i+j]:= x div 10;
   end;
  lenc:=i+j;
  while (c[lenc]=0) and (lenc>1) do
    dec(lenc);
  delete(chen,1,length(chen));
  for i:=lenc downto 1 do
    chen:=chen+chr(c[i]+ord('0'));
end;

by Minclxc @ 2017-03-02 12:49:20

长度,我开256,60分,1000,80分,10000,100分


|