7,763
社区成员
发帖
与我相关
我的任务
分享
Private Sub Form_Load()
s = "9 1 10 6 13"
s1 = "1 2 3 4 5"
s2 = "2 3 4 5 6"
S3 = "3 4 5 6 7"
S4 = "4 5 6 7 8"
S5 = "5 6 7 8 9"
S6 = "6 7 8 9 10"
S7 = "7 8 9 10 11"
S8 = "8 9 10 11 12"
S9 = "9 10 11 12 13"
S10 = "10 11 12 13 14"
arr = Array(s1, s2, S3, S4, S5, S6, S7, S8, S9, S10)
For i = 0 To 9
j = getnum(s, arr(i))
k = k + j
Next
MsgBox k
End Sub
Private Function getnum(ByVal s1 As String, ByVal s2 As String)
Dim a, b
Dim arr() As String
Dim i As Integer, j As Integer, k As Integer, l As Integer
a = Split(s1, " ")
b = Split(s2, " ")
For i = 0 To UBound(a)
For j = 0 To UBound(a)
If a(i) = b(j) Then
ReDim Preserve arr(k)
arr(k) = a(i)
k = k + 1
Exit For
End If
Next
Next
If k >= 3 Then
getnum = 1
For i = 0 To UBound(a)
l = 0
For j = 0 To UBound(arr)
If a(i) <> arr(j) Then
l = l + 1
End If
Next
'Debug.Print l
If l = UBound(arr) + 1 Then
s = s & a(i) & ","
End If
Next
Debug.Print s
Else
getnum = 0
End If
End Function
Option Explicit
Private Function FindCharacter(ByVal Str As String) As Boolean
Dim Str1 As String, Str2 As String
Dim S1() As String, S2() As String, S3() As String
Dim S As String
Dim i As Integer, j As Integer, m As Integer, n As Integer
Str1 = "9 1 10 6 13"
Str2 = Str
S1 = Split(Str1, " "): S2 = Split(Str2, " ")
m = 0: n = 0
For i = 0 To UBound(S1)
For j = 0 To UBound(S2)
If Val(S1(i)) = Val(S2(j)) Then
m = m + 1: S = S & (S1(i) & " ")
Debug.Print "相同的数是:" & S1(i)
End If
Next
Next
n = UBound(S2) + 1 - m
S3 = Split(S, " ")
For i = 0 To UBound(S2)
For j = 0 To UBound(S3)
If Val(S2(i)) = Val(S3(j)) Then
S2(i) = ""
End If
Next
If Len(S2(i)) <> 0 Then Debug.Print "不相同的数是:" & S2(i)
Next
Debug.Print "共有" & m & "个相同的数!", "共有" & n & "个不相同的数!"
FindCharacter = True
End Function
Private Sub Command1_Click()
Dim S9 As String
S9 = "9 10 11 12 13"
FindCharacter (S9)
End Sub