小李根据上述描述,设计了一个统计各段“非重叠块”“重叠块”和剩余段中元素个数的算法。算法的 VB 程序如下,请在划线处填入合适的代码。
Const n = 18: m = 6
Dim a(1 To n) As Integer
Dim b(1 To 2 ∗ m) As Integer
'b(1)、b(2)为第 1 区间的下限和上限,b(3)、b(4)为第2区间的下限和上限,…
Dim c(1 To 2 ∗ m + 1) As Integer
'数组c用于保存统计结果:
'c(1)、c(2)分别存储第1段"非重叠块"和"重叠块"的元素个数,
'c(3)、c(4)分别存储第2段"非重叠块"和"重叠块"的元素个数,…
'c(2m-1)存储第m段"非重叠块"元素个数,c(2m)存储
第m段"重叠块"的元素个数(值为0)
'c(2 m+1)存储剩余段元素个数
Private Sub Command1_Click()
Dim i As Integer, p As Integer, L As Integer, LL
As Integer
'读取n个数据并保存在数组a中,代码略
'读取m个区间的下限和上限并保存在数组b中,代码略
For i = 1 To 2 ∗ m + 1
c(i) = 0
Next i
i = 1: p = 1
L = 0: LL = 0
Do While i <= n And p <= m
If IsIn(i, p)
Then
If Then
LL = LL + 1
Else
L = L + LL + 1
LL = 0
End If
i = i + 1
Else
c(2 ∗ p - 1) = L
c(2 ∗ p) = LL
L = 0
p = p + 1
End If
Loop
If i <= n Then
Else
c(2 ∗ p - 1) = L
c(2 ∗ p) = LL
End If
'输出统计结果,代码略
End Sub
'函数IsIn用来判断a(i)值是否属于第p区间
Function IsIn ( i As Integer, p As Integer )
As Boolean
If a(i) >= b(2 ∗ p - 1) And a(i) <= b(2 ∗ p)
And p <= m Then
IsIn = True
Else
IsIn = False
End If
End Function