本帖最后由 micch 于 2024-7-19 13:07 编辑
- Sub Main()
- ar = Sheet1.Range("A1:c73").Value
- Dim d As New Dictionary
- For i = 2 To UBound(ar)
- If Not d.Exists(ar(i, 1)) Then _
- Set d(ar(i, 1)) = New Dictionary
- d(ar(i, 1)).Add ar(i, 2) & "" & ar(i, 3), 0
- Next
- Sheet1.Range("f2:g11").Value = 0
- br = Sheet1.Range("E2:g11").Value
- For i = 1 To UBound(br)
- DFS d, br(i, 1), br(i, 2), "儿子"
- DFS d, br(i, 1), br(i, 3), "女儿"
- Next
- Sheet1.Range("E2:g11").Value = br
- End Sub
- Function DFS(d0, x0, n0, s0)
- If d0.Exists(x0) Then
- For Each x In d0(x0).Keys
- If InStr(x, s0) Then n0 = n0 + 1
- DFS d0, Mid(x, 3), n0, s0
- Next
- End If
- End Function
复制代码 |