7,762
社区成员
发帖
与我相关
我的任务
分享
Dim data1()
Private Sub Command1_Click()
data1() = Array(1012, 1002, 1004, 987, 988, 1016, 970, 982, 990, 1002, 1011, 1020, 1015, 1014, 1021, 1017, 992, 1027, 1022, 973, 1026, 991, 1001, 1016)
Call Find_continuous_smaller_numbers(data1, 1000, 5)
End Sub
Private Sub Find_continuous_smaller_numbers(data() As Variant, ceiling_number As Integer, link_length As Integer)
Dim i As Integer, n As Integer, m As Integer, j As Integer
For i = 1 To UBound(data)
If data(i) < ceiling_number Then
n = n + 1
Else
m = m + 1
If (m > 1) Then
m = 0
n = 0
End If
End If
If n + m = link_length Then
For j = n To 0 Step -1
Debug.Print data(i - j),
Next j
Debug.Print
Exit For
End If
Next i
End Sub
987 988 1016 970 982
Dim data1(), data2()
Private Sub Command1_Click()
data1() = Array(1012, 1002, 1004, 987, 988, 1016, 970, 982, 990, 1002, 1011, 1020, 1015, 1014, 1021, 1017, 992, 1027, 1022, 973, 1026, 991, 1001, 1016)
data2() = Array(1012, 1002, 1004, 987, 988, 1016, 1020, 1011, 1002, 990, 982, 970, 1015, 1014, 1021, 1017, 992, 1027, 1022, 973, 1026, 991, 1001, 1016)
Call Find_continuous_increasing_numbers(data1, 6)
Call Find_continuous_decreasing_numbers(data2, 6)
End Sub
Private Sub Find_continuous_increasing_numbers(data() As Variant, link_length As Integer)
Dim i As Integer, n As Integer, j As Integer
For i = 1 To UBound(data)
If data(i) > data(i - 1) Then
n = n + 1
Else
n = 0
End If
If n + 1 = link_length Then
For j = n To 0 Step -1
Debug.Print data(i - j),
Next j
Debug.Print
Exit For
End If
Next i
End Sub
Private Sub Find_continuous_decreasing_numbers(data() As Variant, link_length As Integer)
Dim i As Integer, n As Integer, j As Integer
For i = 1 To UBound(data)
If data(i) < data(i - 1) Then
n = n + 1
Else
n = 0
End If
If n + 1 = link_length Then
For j = n To 0 Step -1
Debug.Print data(i - j),
Next j
Debug.Print
Exit For
End If
Next i
End Sub
970 982 990 1002 1011 1020
1020 1011 1002 990 982 970
Sub Test1()
''''一组数中连续6个数递增或递减
Dim i As Integer, lastNum As Integer, w2 As String, ww
Dim k As Integer, S1 As String, nowNum As Integer
ww = Array("1012", "1002", "1004", "987", "988", "1016", "970", "982", "990", "1002", "1011", "1020", "1015", "1014", "1021", "1017", "992", "1027", "1022", "973", "1026", "991", "1001", "1016")
For i = 0 To UBound(ww) - 5
S1 = ww(i)
lastNum = CInt(ww(i))
w2 = ""
For k = i + 1 To i + 5
S1 = S1 & "," & ww(k)
nowNum = CInt(ww(k))
If nowNum < lastNum Then w2 = w2 & "0"
If nowNum > lastNum Then w2 = w2 & "1"
lastNum = nowNum
Next
If w2 = "11111" Or w2 = "00000" Then
Debug.Print S1
Exit For
End If
Next
End Sub
Sub Test2()
''''一组数中连续5个数中有4个小于给定数的组合
Dim i As Integer, nowNum As Integer, Target As Integer
Dim k As Integer, n As Integer, S1 As String, ww
ww = Array("1012", "1002", "1004", "987", "988", "1016", "970", "982", "990", "1002", "1011", "1020", "1015", "1014", "1021", "1017", "992", "1027", "1022", "973", "1026", "991", "1001", "1016")
Target = 1000 ''指定的目标数
For i = 0 To UBound(ww) - 4
S1 = ww(i)
n = 0
If CInt(ww(i)) < Target Then n = 1
For k = i + 1 To i + 4
S1 = S1 & "," & ww(k)
If CInt(ww(k)) < Target Then n = n + 1
Next
If n = 4 Then
Debug.Print S1
Exit For
End If
Next
End Sub
...