實現(xiàn)上述功能的VB程序如下: Private Sub Command1_Click ( ?。?br />Dim a(1To 1000)As String'數(shù)組a存儲文中出現(xiàn)該指定單詞(或字符串)的各個位置 Dim s As String,c As String,ch As String Dim n As Integer,max As Integer,i As Integer s=Text1.Text c=Text2.Text n=0:Max=0 For i=1To Len(s)-Len(c)+1 ch= ① If ch=c Then n=n+1 a(n)=i If n>=2Then If a(n)-a(n-1)-Len(c)>Max Then Max=a(n)-a(n-1)-Len(c) End If End If Next i Text3.Text=② End Sub 以上程序段運行時,為了實現(xiàn)上述功能,橫線處①和②應(yīng)填入的代碼分別為: (1)
. (2)實現(xiàn)上述功能的VB程序如下,請在橫線處填入合適代碼. Dim a(1To 20)As Integer Dim n As Integer Private Sub Text1_KeyPress(KeyAscii As Integer) '將輸入各隊員身高分別存入數(shù)組a中,隊員個數(shù)為n,代碼略! End Sub Private Sub Command1_Click ( ?。?br />Dim c(1To 20)As Integer Dim right As Integer,left As Integer,i As Integer For i=1To n-1 For j=1To n-i If ①
Then t=a(j):a(j)=a(j+1):a(j+1)=t End If Next j Next i ‘下列程序段實現(xiàn)數(shù)組C的合唱隊列 m=(1+n)\2 left=m:right=m c(m)=a(n) i=2 Do While i<=n If i Mod 2=0 Then right=right+1 c(right)=a(n-i+1) Else ②
c(left)=a(n-i+1) End If i=i+1 Loop s=③
For i=2To n s=s+“,“+Str(c(i)) Next i Text2.Text=s End Sub.