|
|
back to boardWhat's wrong with my program? The problem seems to be so easy... I simply multiple N by 2 and then find Trunc(Sqrt(2*N)). Isn't that correct? Why do I get WA? Here is my program: Program Sqrt; Const Max=1300; Var s:String; a,b,c,e:Array[1..Max] Of Byte; v,d,l,p,i,j,k,m,n:Longint; mr:Boolean; Begin Readln(s); l:=Length(s); FillChar(a,SizeOf(a),0); For i:=1 To l Do a[i+1]:=Ord(s[i])-Ord('0'); Inc(l); d:=0; For i:=l DownTo 1 Do Begin v:=a[i]*2+d; b[i]:=v Mod 10; d:=v Div 10; End; Move(b,a,SizeOf(a)); If l Mod 2=1 Then If a[1]>0 Then Begin Inc(l); For i:=l DownTo 2 Do a[i]:=a[i-1]; End Else Begin Dec(l); For i:=1 To l Do a[i]:=a[i+1]; End; FillChar(b,SizeOf(b),0); p:=(l+1) Div 2; For i:=1 To p Do Begin For j:=1 To 9 Do Begin b[i]:=j; FillChar(c,SizeOf(c),0); For k:=i DownTo 1 Do Begin d:=0; For m:=i DownTo 1 Do Begin v:=b[k]*b[m]+d+c[k+m]; c[k+m]:=v Mod 10; d:=v Div 10; End; If d>0 Then c[k]:=c[k]+d; End; mr:=False; For k:=1 To i*2 Do If a[k]<c[k] Then Begin mr:=True; Break; End Else If a[k]>c[k] Then Break; If mr Then Begin Dec(b[i]); Break; End; End; End; i:=1; While b[i]=0 Do Inc(i); For j:=i To p Do Write(b[j]); Writeln; End. Your program gives wrong answer when input is 5050. Posted by abc 19 Dec 2001 15:18 Of course, thank you very much. I should have runned it for such simple tests myself. No I've got AC. Thank you! |
|
|