|
- 'Option Explicit
- Sub Generate羽毛球比赛赛程表()
- Dim teamNames As String, i As Integer, j As Integer, k As Integer
- Dim matchDay As Integer, matchTime As String, matchTeam1 As String, matchTeam2 As String
- Dim matchResult As String, matchWinner As String
-
- '输入参赛队伍名称
- teamNames = InputBox("请输入参赛队伍名称(用空格分隔):")
-
- '将队伍名称转换为数组
- Dim teamArray() As String
- teamArray = Split(teamNames, " ")
- Dim teamArrayLength As Integer
- teamArrayLength = UBound(teamArray) + 1
- '计算每轮比赛的场次和对手匹配情况
- Dim roundCount As Integer, roundMatchCount As Integer
- roundCount = 3
- roundMatchCount = Int((teamArrayLength - 1) * (teamArrayLength - 2) / 2)
-
- '生成第一轮比赛的赛程表
- k = 0
- For i = 0 To UBound(teamArray)
- For j = i + 1 To UBound(teamArray)
- If teamArray(i) <> teamArray(j) Then
- matchDay = Int((i + j) * (i + j + 1) / 2) + k + 1
- matchTime = "9:00" & matchDay & " AM"
- matchTeam1 = teamArray(i) & " vs " & teamArray(j)
- matchTeam2 = teamArray(j) & " vs " & teamArray(i)
- matchResult = ""
- matchWinner = teamArray(i)
-
- '检查是否已经进行了类似的比赛
- For l = k + 1 To roundMatchCount
- If matchTeam1 = teamArray(l Mod teamArrayLength) And matchTeam2 = teamArray((l \ teamArrayLength) Mod teamArrayLength) Then
- matchResult = "T" & l \ roundMatchCount & "" & teamArray(l Mod teamArrayLength) & _
- " vs " & teamArray((l \ teamArrayLength) Mod teamArrayLength) & "" & matchWinner _
- & "" & matchResult & "" & matchWinner & "" & matchResult & "" & matchWinner & "" _
- & matchResult & "" & matchWinner & "" & matchResult & "" & matchWinner & "" & matchResult & "" _
- & matchWinner & "" & matchResult & "" & matchWinner & "" & matchResult & "" & matchWinner & "" _
- & matchResult & "" & matchWinner & "" & matchResult & "" & matchWinner & "" & matchResult & "" _
- & matchWinner & "" & matchResult & "" & matchWinner & "" & matchResult & ""
- Exit For
- End If
- Next l
-
- '输出比赛信息到Excel表格中
- Worksheets("Match Schedule").Cells(matchDay, 2).Value = matchTime
- Worksheets("Match Schedule").Cells(matchDay, 3).Value = matchTeam1
- Worksheets("Match Schedule").Cells(matchDay, 4).Value = matchTeam2
- Worksheets("Match Schedule").Cells(matchDay, 5).Value = matchResult
- Worksheets("Match Schedule").Cells(matchDay, 6).Value = matchWinner
- k = k + 1
- End If
- Next j
- k = k + 1
- Next i
-
- '输出第一轮比赛的赛程表到Excel表格中
- MsgBox Worksheets("Match Schedule").Range("A1").CurrentRegion.Address, _
- vbInformation, "第一轮比赛赛程表"
- End Sub
复制代码 |
|