题型:综合题 题类:常考题 难易度:困难
浙江省高中信息技术 数组练习
例如:如图所示,有4个队8位队员,地上一排格子的数字依次为2、1、1、7、9、2、5、6。若某队甲队员站在第4个格子,则其分数为2+1+1+7=11;乙队员站在第7个格子,则其分数为5+6=11。两者相等,则该队获胜。
gz(1) |
gz(2) |
gz(3) |
gz(4) |
gz(5) |
gz(6) |
gz(7) |
gz(8) |
←→ |
|||||||
2 |
1 |
1 |
7 |
9 |
2 |
5 |
6 |
甲 乙 |
Dim n As Integer
Dim gz(1 To 20) As Integer
Private Sub Command1_Click()
Dim dfa As Integer, dfb As Integer
Dim ta As Integer, tb As Integer
Randomize
For i = 1 To 2 * n
gz(i) = Int(Rnd* 9 + 1)
List1.AddItem “gz(“ & i & ”)” & gz(i)
Next i
num = 1
For j = 1 To 2 * n
ta = j
dfa = zwdf(ta, True)
For k = 1 To 2 * n
tb = k
If dfa = dfb Then
List2.AddItem num & “甲队员(“ & j &”)得分=” & dfa & “乙队员(“ & k & ”)得分=” & dfb
num = num + 1
End If
Next k
Next j
List2.AddItem “获胜的站法共有:”++ “种”
End Sub
Function zwdf(p As Integer, r As Boolean) As Integer
Dim fs As Integer
If r = True Then
fs = fs + gz(i)
Next i
Else
For i = p To 2 * n
fs = fs + gz (i)
Next i
End If
zwdf = fs
End Function
试题篮