|
- Dim xs, d
- Sub tq()
- tt = Timer
- Set d = CreateObject("scripting.dictionary")
- arr = Range("h2:h" & [h65536].End(3).Row)
- ReDim brr(1 To UBound(arr), 1 To 3)
- For i = 1 To UBound(arr) - 1
- x = arr(i, 1)
- For j = i + 1 To UBound(arr)
- y = arr(j, 1)
- If brr(i, 1) = "" And brr(j, 1) = "" Then '两原数均未匹配
- If ISOK(x, y) Then '看两原数是否相似数,有则匹配
- xrr = Split(xs, ",")
- brr(i, 1) = xrr(0): brr(i, 2) = xrr(1): brr(i, 3) = y
- brr(j, 1) = xrr(0): brr(j, 2) = xrr(2): brr(j, 3) = x
- i = i - 1 '指针上移,拿匹配数对照
- Exit For
- End If
- ElseIf brr(i, 1) <> "" And brr(j, 1) = "" Then '上数已有匹配数,拿匹配数对照
- p = brr(i, 1)
- If ISGN(p, y) Then brr(j, 1) = p: brr(j, 2) = xs: brr(j, 3) = x
- End If
- Next
- Next
- [i2].Resize(UBound(arr), 3) = brr
- MsgBox Timer - tt
- End Sub
- Function ISOK(x, y) As Boolean '两原数x,y是否相似,并返回x,y的相似数xs
- xs = "": d.RemoveAll
- For i = 2 To Len(x)
- p = Left(x, i - 1) & Mid(x, i + 1)
- d(p) = i
- Next
-
- For i = 2 To Len(y)
- p = Left(y, i - 1) & Mid(y, i + 1)
- If d.exists(p) Then ISOK = True: Exit For
- Next
-
- If ISOK Then
- xs = p & "," & Mid(x, d(p), 1) & "," & Mid(y, i, 1) 'Like "T5689,3,7",第一位为相似数,第二位为第一个不同数,第三位为第二个不同数
- End If
- End Function
- Function ISGN(p, y) As Boolean '归纳数p是否区配原数y,并返回y中该去掉的数
- xs = "": d.RemoveAll
- d(p) = ""
- For i = 2 To Len(y)
- p = Left(y, i - 1) & Mid(y, i + 1)
- If d.exists(p) Then ISGN = True: Exit For
- Next
- If ISGN Then xs = Mid(y, i, 1)
- End Function
复制代码 |
评分
-
查看全部评分
|