VB 6支篮球队对阵情况

来源:百度知道 编辑:UC知道 时间:2024/05/24 08:48:28
(ABCXYZ)进行比赛,抽签后,A队不和 BCX 队比赛,C不和 BXZ 比赛,6队比赛场数相同,请列出六支队伍的对阵名单。
结果应该是AZ CY BX

不知道是否分主客场,如果分的只要将对阵的先后换下,比如AY和YA两场比赛。
Dim team As Variant, match, str
team = Array("A", "B", "C", "X", "Y", "Z")
str = ""
For i = 0 To 5
For j = i + 1 To 5
match = 1
str2 = team(j)
If InStr("ABCX", team(j)) <> 0 And InStr("ABCX", team(i)) Then
match = 0
End If
If InStr("CBXZ", team(j)) <> 0 And InStr("CBXZ", team(i)) Then
match = 0
End If
If match = 1 Then
str = str + "(" + team(i) + "," + team(j) + ");"
End If
Next
str = str & vbCrLf
Next
MsgBox str

运行结果:
(A,Y);(A,Z);
(B,Y);
(C,Y);
(X,Y);
(Y,Z);
你要求6对比赛场数相同不可能,实际上C不能和ABXZ比赛,只有一场比赛,而Y比赛就比较多。