题型:综合题 题类:常考题 难易度:困难
浙江省2020届高三下学期技术4月联考试卷
小陈根据上述的描述设计了以下的程序,界面如图b所示,单击“初始化”按钮Command 1,按要求生成相关数据存储在数组a中并在列表框List 1中显示,该程序中最外圈不能有地雷,单击“计算”按钮Command 2,对数组a中的数据进行计算并在列表框List 2中输出,输出数据元素的宽度为固定值。
请回答问题:
Const n=9:Const m= 10 'n存储地雷区域大小,m存储地雷数目
Dim a(1 To n*n) As Integer
Private Sub Command 1_Click()
'按要求生成数组a中的数据并在List 1中显示,代码略
End Sub
Private Sub Command 2_Click()
Dim i As Integer, j As Integer, row As Integer
Dim col As Integer, start As Integer, temp As String
For i=1 To n *n
IfThen
row=(i-1)\n+ 1
col=(i-1)Mod n+ 1
For j= 1 To 3
If a(start+col-1) >-1Then a(start+col-1) =a(start+col-1)+1
If a(start+col) >-1Then a(start+col) =a(start+col)+1
If a(start+col+1)>-1Then a(start+col+1) =a(start+col+1)+1
Next j
End If
Next i
List 2.Clear
For i=1To n
temp=“”
For j=1To n
temp=temp+adj(a((i-1) *n+j),3)
Next j
List 2.Add Item temp
Next i
End Sub
Function adj(x As Integer, y As Integer) As String
Dim s As String
s=Str(x)
For i= 1 To
s=“”+s
Next i
adj=s
End Function
试题篮