vb比赛分组抽签程序:编写一个比赛分组抽签程序,把八支队伍(中、美、巴西、古巴、俄罗斯、荷兰、德国、日

本)随机分成A、B两组,每组各四支队伍。求具体编程代码
2025-06-22 16:25:22
推荐回答(3个)
回答1:

Private Sub Command1_Click()

Dim team(8), teamA(4), teamB(4) As String, i%, j%

team(1) = "中国"

team(2) = "美国"

team(3) = "巴西"

team(4) = "古巴"

team(5) = "俄罗斯"

team(6) = "荷兰"

team(7) = "德国"

team(8) = "西班牙"

For i = 1 To 8

    x = Int((9 - i) * Rnd + 1)    '剩余随机选择

    If i > 4 Then

      teamA(i - 4) = team(x)

    Else

      teamB(i) = team(x)

    End If

    For j = x To 8

        If j < 8 Then team(j) = team(j + 1)

    Next

Next

Text1.Text = teamA(1) & Space(2) & teamA(2) & Space(2) & teamA(3) & Space(2) & teamA(4)

Text2.Text = teamB(1) & Space(2) & teamB(2) & Space(2) & teamB(3) & Space(2) & teamB(4)

End Sub

回答2:

1team(1) = "中国"
2team(2) = "美国"
3team(3) = "巴西"
team(4) = "古巴"
team(5) = "俄罗斯"
team(6) = "荷兰"
team(7) = "德国"
team(8) = "西班牙"
For i = 1 To 8
x = Int((9 - i) * Rnd + 1) '剩余随机选择
If i > 4 Then
teamA(i - 4) = team(x)
Else
teamB(i) = team(x)
End If
For j = x To 8
If j < 8 Then team(j) = team(j + 1)
Next
Next
Text1.Text = teamA(1) & Space(2) & teamA(2) & Space(2) & teamA(3) & Space(2) & teamA(4)
Text2.Text = teamB(1) & Space(2) & teamB(2) & Space(2) & teamB(3) & Space(2) & teamB(4)
End Sub

0

回答3:

推荐答案今天 14:15
Private Sub Command1_Click()
Dim team(8), teamA(4), teamB(4) As String, i%, j%
team(1) = "中国"
team(2) = "美国"
team(3) = "巴西"
team(4) = "古巴"
team(5) = "俄罗斯"
team(6) = "荷兰"
team(7) = "德国"
team(8) = "西班牙"
For i = 1 To 8
x = Int((9 - i) * Rnd + 1) '剩余随机选择
If i > 4 Then
teamA(i - 4) = team(x)
Else
teamB(i) = team(x)
End If
For j = x To 8
If j < 8 Then team(j) = team(j + 1)
Next
Next
Text1.Text = teamA(1) & Space(2) & teamA(2) & Space(2) & teamA(3) & Space(2) & teamA(4)
Text2.Text = teamB(1) & Space(2) & teamB(2) & Space(2) & teamB(3) & Space(2) & teamB(4)
End Sub