Dim n As Integer,i As Integer,j As Integer Dim a(1 To 100)As Integer,b(1 To 100)As Integer Dim s As String,chr As String,temp As String s=Text1.Text i=1:n=0 Do While i<=Len(s) ch=Mid(s,i,1) If ch>=“0“And ch<=“9“Then temp=temp+ch Else n=n+1
temp=““ End If i=i+1 Loop For i=2 To n
Next i For i=1 To n-2 For j= If b(j)<b(j-1)Then t=b(j):b(j)=b(j-1):b(j-1)=t End If Next j Next i For i=1 To n-1 If b(i)<>i Then Exit For Next i If i=n Then Label1.Caption=“完美跳數(shù)“ Else Label1.Caption=“非完美跳數(shù)“End Sub (2)請?jiān)谏鲜龀绦虻臋M線處填上合適的代碼。 (3)上述程序加框處代碼有誤,請改正。
。(填個(gè)數(shù)) (2)實(shí)現(xiàn)上述功能的 VB 程序如下,請?jiān)跈M線處填入合適的代碼。 Const n=6 Dim a(1 To n) As Integer Dim m As Integer Private Sub Command1_Click
Dim i As Integer,j As Integer m=0 For i=1 To n a(i)=0'a(i)存儲(chǔ)第 i 行放置棋子的列號(hào) Next i For i=1 To n+1 If i=n+1 Then'所有行棋子放置完畢,輸出一種方案 m=m+1 s=““ For j=1 To n s=s+Str(j)+“:“+Str(a(j))+“|“ Next j List1.AddItem s i=i-2 Else'尋找下一行棋子放置位置 j=a(i)+1 Do While j<=n And check(i,j)=False
Loop If j<=n Then a(i)=j Else a(i)=0
If i<0 Then Exit For End If End If Next i Label1.Caption=“共有“+Str(m)+“種方案“End Sub '判斷當(dāng)前放置的棋子與已放置有無沖突 Function check(i As Integer'j As Integer) As Boolean check=True For k=1 To i-1 If a(k)=j Or j+i=a(k)+k Or