实现上述功能的VB代码如下:
Dim a(1 To 100) As Integer Private Sub Command1_Click()
Dim i As Integer, s As Integer, smax As Integer ‘用于随机生成数据,并将阵列按规则在列表框中输出,该部分功能的代码略。
smax = 0
For i = 1 To 100
If a(i) = 0 Then s = search(i) If s > smax Then smax = s
Next i
Label1.Caption = "最大面积的矩形,占" + Str(smax) + "个单位。" End Sub
Function search(i As Integer) As Integer
Dim x As Integer, x1 As Integer, xend As Integer Dim y As Integer, y1 As Integer
Dim s As Integer
x = (i - 1) Mod 10 + 1 '起始列号 y = (i - 1) \ 10 + 1 '起始行号 x1 = x
y1 = y xend = 10
search = 0
Do While y1 <= 10
If a((y1 - 1) * 10 + x) = 1 Then Exit Do '判断 x1 = x
Do While x1 <= xend
If a((y1 - 1) * 10 + x1) = 1 Then
x1 = x1 – 1 '改错
Else
x1 = x1 + 1
End If Loop
y1 = y1 + 1
s = (x1 - x) * ( ) '填空 If s > search Then search = s
Loop
End Function
请回答下列问题: