'
Option Explicit
'
Sub abc()
Dim a, i, j, k, cnt
a = [a1].CurrentRegion.Resize(, 1).Value
cnt = Len(a(1, 1))
For i = 2 To UBound(a)
If Len(a(i, 1)) < cnt Then cnt = Len(a(i, 1))
Next
ReDim d(cnt)
For i = 0 To UBound(d)
Set d(i) = CreateObject("scripting.dictionary")
Next
For i = 1 To UBound(a)
For j = 2 To cnt '最小组合数为2
For k = 1 To Len(a(i, 1)) - j + 1
d(j)(Mid(a(i, 1), k, j)) = d(j)(Mid(a(i, 1), k, j)) + 1
Next
Next
Next
cnt = 0
ReDim a(1 To 10 ^ 5, 1 To 2)
For i = 2 To UBound(d)
For Each j In d(i).keys
cnt = cnt + 1
a(cnt, 1) = j: a(cnt, 2) = d(i)(j)
Next
Next
If cnt > 1 Then Call qsort(a, 1, cnt, 1, 2, 2)
[c1].Resize(cnt, 2) = a
End Sub
'
Function qsort(a, first, last, left, right, key)
Dim i As Long, j As Long, k As Long, x, t
i = first: j = last: x = a((first + last) \ 2, key)
While i <= j
While a(i, key) > x: i = i + 1: Wend
While x > a(j, key): j = j - 1: Wend
If i <= j Then
For k = left To right
t = a(i, k): a(i, k) = a(j, k): a(j, k) = t
Next
i = i + 1: j = j - 1
End If
Wend
If first < j Then qsort a, first, j, left, right, key
If i < last Then qsort a, i, last, left, right, key
End Function