|
'应该有7+1种组合,因为有都不参加的。所有组合全部输出
Option Explicit
Sub test()
Dim arr, i, j, k, kk, t, key, n, mark
ReDim dic(1 To 5)
For i = 1 To UBound(dic)
Set dic(i) = CreateObject("scripting.dictionary")
Next
mark = Split("一 二 三")
For i = 0 To UBound(mark): dic(5)(mark(i) & "类宾客") = i + 1: Next
arr = ActiveSheet.UsedRange
For i = 2 To UBound(arr, 1)
If Len(arr(i, 1)) = 0 Then Exit For
dic(4)(arr(i, 1)) = arr(i, 2)
Next
For i = 1 To 3
For j = 2 To UBound(arr, 1)
If Len(arr(j, 2 * i + 5)) = 0 Then Exit For
If Not dic(i).exists(arr(j, 2 * i + 5)) Then
dic(i)(arr(j, 2 * i + 5)) = dic(4)(arr(j, 2 * i + 5))
End If
Next j, i
For i = 1 To 3
ReDim cnt(1 To 3)
For Each key In dic(i).keys
cnt(dic(5)(dic(i)(key))) = cnt(dic(5)(dic(i)(key))) + 1
Next
Debug.Print i & "号桌3类客人分别为:" & Join(cnt, ",")
Next
Debug.Print String(30, "-")
ReDim arr(1 To dic(4).Count + 1, 1 To 2) As String
For Each key In dic(4).keys
mark = vbNullString: n = n + 1
For i = 1 To 3
mark = mark & IIf(dic(i).exists(key), "1", "0")
Next
arr(n, 1) = mark: arr(n, 2) = dic(4)(key)
Next
For i = 1 To UBound(arr, 1) - 2
For j = i + 1 To UBound(arr, 1) - 1
If arr(i, 1) > arr(j, 1) Then
t = arr(i, 1): arr(i, 1) = arr(j, 1): arr(j, 1) = t
t = arr(i, 2): arr(i, 2) = arr(j, 2): arr(j, 2) = t
End If
Next j, i
mark = Split("000 不参加 100 一号 010 二号 001 三号 110 一二号 101 一三号 011 二三号 111 一二三号")
For i = 0 To UBound(mark) Step 2
ReDim cnt(1 To 3)
For j = 1 To UBound(arr, 1)
If arr(j, 1) = mark(i) Then
For k = j To UBound(arr, 1)
If arr(k, 1) <> mark(i) Then
For kk = 1 To 3
If Len(cnt(kk)) = 0 Then cnt(kk) = 0
Next
Debug.Print mark(i + 1) & "桌3类客人分别为:" & Join(cnt, ",")
j = UBound(arr, 1): Exit For
End If
cnt(dic(5)(arr(k, 2))) = cnt(dic(5)(arr(k, 2))) + 1
Next
End If
Next j, i
End Sub |
评分
-
1
查看全部评分
-
|