1,451
社区成员
发帖
与我相关
我的任务
分享
6 9 7 9 3 3->9
1 2 4 2 4 8->2 4
8 6 7 9 7 9->7
7 9 3 3 1 2->3
5 4 1 4 5 6->4 5
0 7 0 7 0 1->7 0
2 6 3 5 2 5->2
6 7 1 8 0 7->7
For i = 0 To UBound(aNum) - 5 Step 6
Option Explicit
Public Sub Main()
Const LIST As String = "3 1 3 7 7 5 6 " & _
"9 7 9 3 3 1 2 " & _
"4 2 4 8 8 6 7 " & _
"9 7 9 3 3 1 2 " & _
"6 4 6 0 0 8 9 " & _
"9 7 9 3 3 1 2 " & _
"2 0 2 6 6 4 5 " & _
"4 1 4 5 6 0 7 " & _
"0 7 0 1 2 6 3 " & _
"5 2 5 6 7 1 8 " & _
"0 7 0 1 2 6 3 " & _
"7 4 7 8 9 3 0"
Dim aNum() As String
Dim aDup() As Boolean, lDupCount As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim l As Long
aNum = Split(LIST, " ")
For i = 0 To UBound(aNum) - 5
ReDim aDup(3 To 5)
lDupCount = 0
For j = 3 To 5 '循环后3个'
For k = 0 To 2
If aNum(i + j) = aNum(i + k) Then '是否与前3个中任意一个相等'
aDup(j) = True
For l = 3 To j - 1
If aNum(i + j) = aNum(i + l) Then '是否已经出现过相同的相等'
aDup(j) = False
Exit For
End If
Next
If aDup(j) Then
lDupCount = lDupCount + 1
End If
End If
Next
Next
If lDupCount > 0 Then
For j = 0 To 5
If j > 0 Then Debug.Print " ";
Debug.Print aNum(i + j);
Next
Debug.Print "->";
For j = 3 To 5
If aDup(j) Then
Debug.Print aNum(i + j) & " ";
End If
Next
Debug.Print
End If
Next
End Sub
Private Sub Command1_Click()
Dim nums As String
nums = "3 1 3 7 7 5 6 " & _
"9 7 9 3 3 1 2 " & _
"4 2 4 8 8 6 7 " & _
"9 7 9 3 3 1 2 " & _
"6 4 6 0 0 8 9 " & _
"9 7 9 3 3 1 2 " & _
"2 0 2 6 6 4 5 " & _
"4 1 4 5 6 0 7 " & _
"0 7 0 1 2 6 3 " & _
"5 2 5 6 7 1 8 " & _
"0 7 0 1 2 6 3 " & _
"7 4 7 8 9 3 0 "
Debug.Print GetCrossNum(nums)
End Sub
Private Function GetCrossNum(ByVal vStr As String) As String
Dim mString As String
Dim i As Long, j As Long, k As Integer
Dim arrTmp() As String
arrTmp = Split(vStr, " ")
For i = 0 To UBound(arrTmp)
If k = 3 Then
' Debug.Print "------" '可以用某个符号来区分每组6个数的相交数
i = i + 3
k = 0
Else
If i + 3 - k <= UBound(arrTmp) Then
If i + 5 - k <= UBound(arrTmp) Then
For j = i + 3 - k To i + 5 - k
If arrTmp(i) = arrTmp(j) Then
mString = mString & " " & arrTmp(i)
Exit For
End If
Next
Else '最后还留不多于6个数
For j = i + 3 - k To UBound(arrTmp)
If arrTmp(i) = arrTmp(j) Then
mString = mString & " " & arrTmp(i)
Exit For
End If
Next
End If
Else '最后还留不多余3个数
Exit For
End If
End If
k = k + 1
Next
GetCrossNum = mString
End Function
Function GetValue(ByVal pStr As String) As String
Dim i As Long
Dim lng(9) As Long
Dim arr
arr = Split(pStr, Chr(32))
For i = 0 To 2
lng(arr(i)) = lng(arr(i)) + 1
Next
For i = 3 To 5
If lng(arr(i)) > 0 Then
GetValue = GetValue & arr(i)
lng(arr(i)) = 0
End If
Next
End Function
Private Sub Command1_Click()
Debug.Print GetValue("3 1 3 7 7 5")
Debug.Print GetValue("6 9 7 9 3 3")
Debug.Print GetValue("1 2 4 2 4 8")
Debug.Print GetValue("8 6 7 9 7 9")
Debug.Print GetValue("1 2 3 3 2 2")
End Sub
Option Explicit
Private Sub Command1_Click()
Dim nums As String
nums = "3 1 3 7 7 5 6 " & _
"9 7 9 3 3 1 2 " & _
"4 2 4 8 8 6 7 " & _
"9 7 9 3 3 1 2 " & _
"6 4 6 0 0 8 9 " & _
"9 7 9 3 3 1 2 " & _
"2 0 2 6 6 4 5 " & _
"4 1 4 5 6 0 7 " & _
"0 7 0 1 2 6 3 " & _
"5 2 5 6 7 1 8 " & _
"0 7 0 1 2 6 3 " & _
"7 4 7 8 9 3 0 "
Dim i As Long, j As Long, k As Integer
Dim arrTmp() As String
arrTmp = Split(nums, " ")
For i = 0 To UBound(arrTmp)
If k = 3 Then
' Debug.Print "------" '可以用某个符号来区分每组6个数的相交数
i = i + 3
k = 0
Else
If i + 3 - k <= UBound(arrTmp) Then
If i + 5 - k <= UBound(arrTmp) Then
For j = i + 3 - k To i + 5 - k
If arrTmp(i) = arrTmp(j) Then
Debug.Print arrTmp(i)
Exit For
End If
Next
Else '最后还留不多于6个数
For j = i + 3 - k To UBound(arrTmp)
If arrTmp(i) = arrTmp(j) Then
Debug.Print arrTmp(i)
Exit For
End If
Next
End If
Else '最后还留不多余3个数
Exit For
End If
End If
k = k + 1
Next
End Sub
Option Explicit
Private Sub Command1_Click()
Dim str As String
str = "3 1 3 7 7 5 6 ," & _
"9 7 9 3 3 1 2 ," & _
"4 2 4 8 8 6 7 ," & _
"9 1 3 3 3 1 2 ," & _
"6 4 6 0 0 8 9 ," & _
"9 7 9 3 3 1 2 ," & _
"2 6 2 6 6 4 5 ," & _
"4 1 4 5 6 0 7 ," & _
"0 7 0 1 2 6 3 ," & _
"5 2 5 6 7 1 8 ," & _
"0 7 0 1 2 6 3 ," & _
"7 4 7 8 9 3 0 ,"
Dim i As Long
For i = 0 To 8
str = str & str
Next
Debug.Print Len(str)
Dim cross_data As String
cross_data = return_cross_data(str)
Debug.Print cross_data
Debug.Print Len(cross_data)
End Sub
Private Function return_cross_data(ByRef str As String) As String
Dim in_data() As String
Dim in_data_line() As String
Dim s As String
in_data = Split(str, ",")
Dim iCount As Long
iCount = UBound(in_data)
Dim i As Long
For i = 0 To iCount - 1
s = s & new_process_line_data(in_data(i)) & vbCrLf
Next
return_cross_data = s
End Function
Private Function process_line_data(ByVal line As String) As String
Dim bLine() As Byte
Dim i As Long
Dim ii As Long
Dim iCount As Long
Dim bNoMatch As Boolean
Dim s As String
bLine = line
bNoMatch = False
For i = 0 To 11 Step 4
For ii = 12 To 20 Step 4
If (bLine(i) = bLine(ii)) Then
bNoMatch = True
If Len(s) <> 0 Then
s = s & "|" & Chr(bLine(i))
Else
s = s & line & "->" & Chr(bLine(i))
End If
Exit For
End If
Next
Next
If Not bNoMatch Then
process_line_data = line & "->no match"
Else
process_line_data = s
End If
End Function
Private Function new_process_line_data(ByVal line As String) As String
Dim bLine() As String
Dim i As Long
Dim ii As Long
Dim iCount As Long
Dim bNoMatch As Boolean
Dim s As String
bLine = Split(line, " ")
bNoMatch = False
For i = 0 To 2
For ii = 3 To 5
If (bLine(i) = bLine(ii)) Then
bNoMatch = True
If Len(s) <> 0 Then
s = s & "|" & bLine(i)
Else
s = s & line & "->" & bLine(i)
End If
Exit For
End If
Next
Next
If Not bNoMatch Then
new_process_line_data = line & "->no match"
Else
new_process_line_data = s
End If
End Function
Option Explicit
Private Sub Command1_Click()
Dim nums As String
nums = "3 1 3 7 7 5 6 " & _
"9 7 9 3 3 1 2 " & _
"4 2 4 8 8 6 7 " & _
"9 7 9 3 3 1 2 " & _
"6 4 6 0 0 8 9 " & _
"9 7 9 3 3 1 2 " & _
"2 0 2 6 6 4 5 " & _
"4 1 4 5 6 0 7 " & _
"0 7 0 1 2 6 3 " & _
"5 2 5 6 7 1 8 " & _
"0 7 0 1 2 6 3 " & _
"7 4 7 8 9 3 0 "
Debug.Print "相交数:" & Trim(GetCrossNum(nums))
End Sub
Private Function GetCrossNum(ByVal vStr As String) As String
Dim mString As String
Dim strOF As String, strSame(2) As String
Dim i As Long, j As Long, k As Integer
Dim strTmp As String
Dim arrTmp() As String
arrTmp = Split(vStr, " ")
For i = 0 To UBound(arrTmp)
If k = 3 Then
strOF = ""
strTmp = ""
For j = i - 3 To i + 2
strOF = strOF & " " & arrTmp(j)
Next
If strSame(0) = "" And strSame(1) = "" And strSame(2) = "" Then
Else
If strSame(0) = strSame(1) Or strSame(0) = strSame(2) Then
strSame(0) = ""
Else
If strSame(1) = strSame(2) Then
strSame(1) = ""
End If
End If
strTmp = strSame(0) & " " & strSame(1) & " " & strSame(2)
Debug.Print Trim(strTmp) & "---" & strOF
mString = mString & IIf(mString = "", Trim(strTmp), " " & Trim(strTmp))
End If
i = i + 2
k = -1
Erase strSame
Else
If i + 3 - k <= UBound(arrTmp) Then
If i + 5 - k <= UBound(arrTmp) Then
For j = i + 3 - k To i + 5 - k
If Val(arrTmp(i)) = Val(arrTmp(j)) Then
' Debug.Print arrTmp(i)
strSame(k) = arrTmp(i)
Exit For
End If
Next
Else '最后还留不多于6个数
For j = i + 3 - k To UBound(arrTmp)
If Val(arrTmp(i)) = Val(arrTmp(j)) Then
' Debug.Print arrTmp(i)
strSame(k) = arrTmp(i)
Exit For
End If
Next
End If
Else '最后还留不多余3个数
Exit For
End If
End If
k = k + 1
Next
GetCrossNum = mString
End Function
Public Sub Main()
Const LIST As String = "3 1 3 7 7 5 6 " & _
"9 7 9 3 3 1 2 " & _
"4 2 4 8 8 6 7 " & _
"9 7 9 3 3 1 2 " & _
"6 4 6 0 0 8 9 " & _
"9 7 9 3 3 1 2 " & _
"2 0 2 6 6 4 5 " & _
"4 1 4 5 6 0 7 " & _
"0 7 0 1 2 6 3 " & _
"5 2 5 6 7 1 8 " & _
"0 7 0 1 2 6 3 " & _
"7 4 7 8 9 3 0"
Dim aNum() As String
Dim aDup() As Boolean, lDupCount As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim l As Long
aNum = Split(LIST, " ")
For i = 0 To UBound(aNum) - 5
ReDim aDup(3 To 5)
lDupCount = 0
For j = 3 To 5 '循环后3个'
For k = 0 To 2
If aNum(i + j) = aNum(i + k) Then '是否与前3个中任意一个相等'
aDup(j) = True
For l = 3 To j - 1
If aNum(i + j) = aNum(i + l) Then '是否已经出现过相同的相等'
aDup(j) = False
Exit For
End If
Next
If aDup(j) Then
lDupCount = lDupCount + 1
End If
End If
Next
Next
If lDupCount > 0 Then
' For j = 0 To 5
' If j > 0 Then Debug.Print " ";
' Debug.Print aNum(i + j);
' Next
' Debug.Print "->";
For j = 3 To 5
If aDup(j) Then
Debug.Print aNum(i + j) & " ";
End If
Next
Debug.Print
End If
Next
End Sub