老师布置的
是为做算24点做准备要求就是我的标题。。
用循环语句我刚学不久。。
所以菜呵呵。
是为做算24点做准备要求就是我的标题。。
用循环语句我刚学不久。。
所以菜呵呵。
解决方案 »
- VB串口通信:如何接收缓存中的多条数据,并在多个text中显示出来?
- winsock建立连接后还未发生Connect事件已经激活了DataArrival事件怎么办?
- 随机密码生成问题
- 请问Treeview怎么交换节点位置呀
- vb中的错误提示BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录
- 关于vb读写内存,openprocess和ReadProcessMemory的问题。。。。在线等待
- 网络数据库的问题
- 何为水晶报表?用vb可以开发吗?怎么开发?
- treeview莫名其妙的问题
- 在Combo中我只知道一个项的TEXT,不知道INDEX,怎么将这项删除?
- 一个简单的数据类型的问题
- 高手求救(改变系统分辨率的情况下,图象随之改变)
Dim a(8) As String, temp As String
For i = 0 To 8
a(i) = i
Next
temp = permutation(a, UBound(a))
Debug.Print temp
Debug.Print "共有 " & UBound(Split(temp, vbCrLf)) + 1 & " 种排法!"
End Sub
Function addxtostr(ByVal x0 As String, ByVal xadd As String) As String ' eg: x0: "1,2,3,4",we will add 5 to x0
Dim temp, temp2, all() As String, i As Long
temp = Split(x0, ",")
ReDim all(UBound(temp) + 1)
all(0) = xadd & "," & x0 ' return "5,1,2,3,4"
For i = 1 To UBound(all)
temp2 = temp
temp2(i - 1) = temp2(i - 1) & "," & xadd ' add 5 between every two contunious number
all(i) = Join(temp2, ",")
Next
addxtostr = Join(all, vbCrLf)
Set temp = Nothing
Set temp2 = Nothing
Erase all
End Function
Function permutation(ByRef a() As String, ByVal n As Long) As String '列出数组a 的前n-1 个元素的全排列
Dim i As Long, temp, all() As String
If n = 0 Then permutation = a(0)
If n = 1 Then permutation = a(0) & "," & a(1) & vbCrLf & a(1) & "," & a(0)
If n > 1 Then
temp = Split(permutation(a, n ), vbCrLf) ' 递归
ReDim all(UBound(temp))
For i = 0 To UBound(temp)
all(i) = addxtostr(temp(i), a(n))
Next
permutation = Join(all, vbCrLf)
End If
Erase all
End Function