Option Explicit
Private Sub isexist(ByVal SubN As Integer, ByRef tempArr() As Integer)
Dim ArrayTemp(99) As Integer '从1-100的数字临时数组
Dim temp As Integer
Dim tempRnd As Integer
Dim i As Integer
Dim TempMaxArray As Integer
TempMaxArray = UBound(tempArr)
For i = 1 To 100
ArrayTemp(i - 1) = i '生成选择数据
Next i
i = 0
Randomize Now
Do While i <= TempMaxArray
tempRnd = CInt(100 * Rnd)
temp = ArrayTemp(tempRnd)
If temp <> 0 Then
tempArr(i) = temp
i = i + 1
ArrayTemp(tempRnd) = 0
End If
Loop
End Sub
Private Sub Command1_Click()
Me.AutoRedraw = True
Me.Cls
Dim ArrayRnd(19) As Integer '生成的随机数数组
Dim i As Integer
Dim j As Integer
Dim tempSum(19) As Integer
Dim MaxIndex As Integer
isexist 20, ArrayRnd
For i = 0 To UBound(ArrayRnd)
Print ArrayRnd(i) '验证不重复的随机数
tempSum(i) = 0
For j = 0 To 3
If i + j < UBound(ArrayRnd) Then
tempSum(i) = tempSum(i) + ArrayRnd(i + j)
Else
tempSum(i) = tempSum(i) + ArrayRnd(j)
End If
Next j
Next i
Dim TempMax As Integer
TempMax = 0
Print "************************************"
For i = 0 To UBound(tempSum)
Print tempSum(i)
If tempSum(i) > TempMax Then
MaxIndex = i
TempMax = tempSum(i)
End If
Next i
Dim tempStr As String
For i = 0 To 3
If MaxIndex < UBound(ArrayRnd) + i Then
tempStr = tempStr & ArrayRnd(MaxIndex + i) & "+"
Else
tempStr = tempStr & ArrayRnd(i) & "+"
End If
Next i
Print "************************************"
Print Left(tempStr, Len(tempStr) - 1) & "(MaxSum)=" & tempSum(MaxIndex) & ";" & MaxIndex
End Sub
Private Sub isexist(ByVal SubN As Integer, ByRef tempArr() As Integer)
Dim ArrayTemp(99) As Integer '从1-100的数字临时数组
Dim temp As Integer
Dim tempRnd As Integer
Dim i As Integer
Dim TempMaxArray As Integer
TempMaxArray = UBound(tempArr)
For i = 1 To 100
ArrayTemp(i - 1) = i '生成选择数据
Next i
i = 0
Randomize Now
Do While i <= TempMaxArray
tempRnd = CInt(100 * Rnd)
temp = ArrayTemp(tempRnd)
If temp <> 0 Then
tempArr(i) = temp
i = i + 1
ArrayTemp(tempRnd) = 0
End If
Loop
End Sub
Private Sub Command1_Click()
Me.AutoRedraw = True
Me.Cls
Dim ArrayRnd(19) As Integer '生成的随机数数组
Dim i As Integer
Dim j As Integer
Dim tempSum(19) As Integer
Dim MaxIndex As Integer
isexist 20, ArrayRnd
For i = 0 To UBound(ArrayRnd)
Print ArrayRnd(i) '验证不重复的随机数
tempSum(i) = 0
For j = 0 To 3
If i + j < UBound(ArrayRnd) Then
tempSum(i) = tempSum(i) + ArrayRnd(i + j)
Else
tempSum(i) = tempSum(i) + ArrayRnd(j)
End If
Next j
Next i
Dim TempMax As Integer
TempMax = 0
Print "************************************"
For i = 0 To UBound(tempSum)
Print tempSum(i)
If tempSum(i) > TempMax Then
MaxIndex = i
TempMax = tempSum(i)
End If
Next i
Dim tempStr As String
For i = 0 To 3
If MaxIndex < UBound(ArrayRnd) + i Then
tempStr = tempStr & ArrayRnd(MaxIndex + i) & "+"
Else
tempStr = tempStr & ArrayRnd(i) & "+"
End If
Next i
Print "************************************"
Print Left(tempStr, Len(tempStr) - 1) & "(MaxSum)=" & tempSum(MaxIndex) & ";" & MaxIndex
End Sub