|
本帖最后由 一把小刀闯天下 于 2018-7-25 16:05 编辑
‘进入猜题模式,好像差不多。三楼附件
Option Explicit
Sub test()
Dim arr, brr, crr, dic, drr, temp, t As String, key, offset
Dim i As Long, j As Long, k As Long, kk As Long, m As Long
Set dic = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
With Sheets("sheet1")
arr = .Range("d1:d" & .Cells(Rows.Count, "d").End(xlUp).Row + 1)
brr = .[g1].CurrentRegion
End With
ReDim crr(1 To UBound(brr, 1), 1 To UBound(brr, 2) - 60) As String
ReDim drr(1 To UBound(brr, 1)) As String: temp = drr
Sheets("结果").Cells.ClearContents
For i = 1 To UBound(arr, 1) - 1
If Len(arr(i, 1)) > 0 Then
For j = 1 To UBound(brr, 2) - 60
dic.RemoveAll: m = 0
For k = j To j + 59
For kk = 1 To UBound(brr, 1)
If Len(brr(kk, k)) = 0 Then Exit For
dic(brr(kk, k)) = dic(brr(kk, k)) + 1
Next kk, k
For Each key In dic.keys
If dic(key) = arr(i, 1) Then
m = m + 1: drr(m) = key
End If
Next
If m > 0 Then
Call msort(drr, CLng(1), CLng(m), temp)
For k = 1 To m: crr(k, j) = drr(k): Next
End If
Next
End If
Sheets("结果").[b1].offset(, offset).Resize(UBound(crr, 1), UBound(crr, 2)) = crr
offset = offset + UBound(crr, 2) + 1
Next
Application.ScreenUpdating = True
End Sub
Function msort(arr, first, last, temp)
Dim i As Long, j As Long, k As Long, mid As Long
If first <> last Then
mid = Int((first + last) / 2)
msort arr, first, mid, temp
msort arr, mid + 1, last, temp
i = first: j = mid + 1: k = first
While i <= mid And j <= last
If arr(i) <= arr(j) Then
temp(k) = arr(i): k = k + 1: i = i + 1
Else
temp(k) = arr(j): k = k + 1: j = j + 1
End If
Wend
While i <= mid
temp(k) = arr(i): k = k + 1: i = i + 1
Wend
While j <= last
temp(k) = arr(j): k = k + 1: j = j + 1
Wend
For i = first To last: arr(i) = temp(i): Next
End If
End Function
|
评分
-
1
查看全部评分
-
|