Pascal求救

P1303 A*B Problem

Hcf2002 @ 2017-07-10 10:18:12

*各种数据套进去都对了。。但是WA了最后两个点。。求dalao帮忙看看或者提供一些数据*

var a,b,max,min:string;
    ans,i,j,l1,l2,g,single,k,single2,zero:longint;
    p:string;
function plus(a,b:string):string;
var l,i,g:longint;
    c:ansistring;
    p:char;
begin
 while length(a) < length(b) do a:='0'+a;
 while length(a) > length(b) do b:='0'+b;
 l:=length(a);
 g:=0;
 for i:=l downto 1 do
    begin
      p:=chr(ord(a[i])+ord(b[i])-48+g);
      if p > '9' then
        begin
          p:=chr(ord(p)-57+47);
          g:=1;
        end
      else g:=0;
      c:=p+c;
    end;
 if g=1 then c:='1'+c;
 exit(c);
end;
begin
  readln(a);
  readln(b);
  if (a='0')or(b='0') then
    begin
      writeln(0);
      halt;
    end;
  if length(a) < length(b) then
     begin
       max:=b;
       min:=a;
     end
  else begin
      max:=a;
      min:=b;
     end;
  l1:=length(max);
  l2:=length(min);
  zero:=0;
  while min[l2]='0' do
     begin
       delete(min,l2,1);
       dec(l2);
       inc(zero);
     end;
  g:=0;
  a:='0';
  for i:=l2 downto 1 do
     begin
       g:=0;
       delete(b,1,length(b));
       val(min[i],k);
       for j:=l1 downto 1 do
         begin
           val(max[j],single);
           single2:=single;
           single:=(k*single+g) mod 10;
           g:=(k*single2+g) div 10;
           str(single,p);
           b:=p+b;
         end;
       if g <> 0 then
         begin
           str(g,p);
           b:=p+b;
         end;
       ans:=l2-i;
       while ans > 0 do
          begin
            b:=b+'0';
            dec(ans);
          end;
       a:=plus(a,b);
    end;
while zero > 0 do
  begin
    a:=a+'0';
    dec(zero);
  end;
writeln(a);
end.

by 1767629007F @ 2017-07-10 11:14:06

嘿嘿嘿


|