|
|
back to boardWhat's wrong with my code? Posted by superzn 27 Jan 2002 20:03 var a,c,x:array[1..1400] of integer; b:array[1..700] of integer; ch:char; d,i,j,k,g,t,o,cl,xl:integer; ss:string; function comp:boolean; var i,j:integer; begin if cl<xl then comp:=true else if cl>xl then comp:=false else begin j:=0; for i:=cl downto 1 do if c[i]<>x[i] then begin j:=1;break; end; if (j=0) or (c[i]<x[i]) then comp:=true else comp:=false; end; end; begin fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); t:=0; while not eoln do begin read(ch);inc(t); a[t]:=ord(ch)-48; end; for i:=1 to t div 2 do begin j:=a[i];a[i]:=a[t-i+1];a[t-i+1]:=j; end; if (t=1) and (a[1]=0) then begin writeln(0);halt; end; o:=0; for i:=1 to t do begin o:=a[i]*2+o; a[i]:=o mod 10; o:=o div 10; end; if o>0 then begin inc(t);a[t]:=o; end; d:=(t+1) div 2; for i:=(d-1)*2+1 to t do x[i-(d-1)*2]:=a[i]; xl:=t-(d-1)*2; cl:=0;b[d]:=0; while comp do begin inc(b[d]);g:=sqr(b[d]);cl:=0; while g>0 do begin inc(cl);c[cl]:=g mod 10; g:=g div 10; end; end; dec(b[d]);g:=sqr(b[d]);cl:=0; while g>0 do begin inc(cl);c[cl]:=g mod 10; g:=g div 10; end; o:=0; for i:=1 to xl do begin o:=x[i]-c[i]+o; if o>=0 then begin x[i]:=o;o:=0; end else begin x[i]:=o+10;o:=-1; end; end; while (xl>0) and (x[xl]=0) do dec(xl); for i:=d-1 downto 1 do begin for j:=xl downto 1 do x[j+2]:=x[j]; x[1]:=a[(i-1)*2+1];x[2]:=a[(i-1)*2+2]; xl:=xl+2; b[i]:=0; repeat inc(b[i]); fillchar(c,sizeof(c),0); o:=0;cl:=0; for j:=i+1 to d do begin o:=b[j]*b[i]*20+o; inc(cl);c[cl]:=o mod 10; o:=o div 10; end; while o>0 do begin inc(cl);c[cl]:=o mod 10; o:=o div 10; end; o:=sqr(b[i]);j:=0; while o>0 do begin inc(j);o:=c[j]+o; c[j]:=o mod 10; o:=o div 10; end; if j>cl then cl:=j; until not comp; dec(b[i]); fillchar(c,sizeof(c),0); o:=0;cl:=0; for j:=i+1 to d do begin o:=b[j]*b[i]*20+o; inc(cl);c[cl]:=o mod 10; o:=o div 10; end; while o>0 do begin inc(cl);c[cl]:=o mod 10; o:=o div 10; end; o:=sqr(b[i]);j:=0; while o>0 do begin inc(j);o:=c[j]+o; c[j]:=o mod 10; o:=o div 10; end; if j>cl then cl:=j; o:=0; for j:=1 to xl do begin o:=x[j]-c[j]+o; if o>=0 then begin x[j]:=o;o:=0; end else begin x[j]:=o+10;o:=-1; end; end; while (xl>0) and (x[xl]=0) do dec(xl); end; for i:=d downto 1 do write(b[i]); writeln; end. |
|
|