求VB写出11个数字取五个数组成的全排列,不重复 假定为1到11即可
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/21 00:19:37
求VB写出11个数字取五个数组成的全排列,不重复 假定为1到11即可
求VB写出11个数字取五个数组成的全排列,不重复 假定为1到11即可
求VB写出11个数字取五个数组成的全排列,不重复 假定为1到11即可
运行时间很长的,请耐心等待:
Private Function Ps(Za As Integer, Zb As Integer, Zc As Integer, Zd As Integer, Ze As Integer)
Dim I1 As Integer, I2 As Integer, I3 As Integer, I4 As Integer, I5 As Integer
Dim Zf(1 To 5) As String, Xzf(1 To 5) As String
Zf(1) = Za
Zf(2) = Zb
Zf(3) = Zc
Zf(4) = Zd
Zf(5) = Ze
For I1 = 1 To 5
Xzf(1) = Zf(I1)
For I2 = 1 To 5
Xzf(2) = Zf(I2)
If Xzf(1) = Xzf(2) Then GoTo L2
For I3 = 1 To 5
Xzf(3) = Zf(I3)
If Xzf(3) = Xzf(1) Or Xzf(3) = Xzf(2) Then GoTo L3
For I4 = 1 To 5
Xzf(4) = Zf(I4)
If Zf(I4) = Xzf(1) Or Zf(I4) = Xzf(2) Or Zf(I4) = Xzf(3) Then GoTo L4
For I5 = 1 To 5
Xzf(5) = Zf(I5)
If Xzf(5) Zf(I4) And Xzf(5) Xzf(3) And Xzf(5) Xzf(2) And Xzf(5) Xzf(1) Then
Open App.Path & "\排列.txt" For Append As #1
Print #1, Xzf(1) & Xzf(2) & Xzf(3) & Zf(I4) & Xzf(5),
Close #1
End If
Next I5
'Print
L4:
Next I4
L3:
Next I3
L2:
Next I2
Next I1
End Function
Private Sub Command1_Click()
Dim I1 As Integer, I2 As Integer, I3 As Integer, I4 As Integer, I5 As Integer
Dim Sz(1 To 11)
Open App.Path & "\排列.txt" For Output As #1
Close #1
For I1 = 1 To 7
For I2 = I1 + 1 To 8
For I3 = I1 + 2 To 9
For I4 = I1 + 3 To 10
For I5 = I1 + 4 To 11
DoEvents
Label1 = I1 & I2 & I3 & I4 & I5
Ps I1, I2, I3, I4, I5
Next I5, I4, I3, I2, I1
Label1 = "完成,结果保存在" & App.Path & "\排列.txt"
End Sub