VB 编程问题(排列组合)
我想写一个,比如在text1中输入数值,单击Command1,能显示出排列顺序排列里只有0和1然后筛选0<=1的显示在Label1中例如输入3则显示01111110111...
我想写一个,比如在text1中输入数值,单击Command1,能显示出 排列顺序
排列里只有 0和1
然后筛选 0 <= 1 的显示在 Label1 中
例如 输入 3
则显示 011
111
101
110
谢谢,高手
a和b两个数字,每组8位,如下:
aaaaaaaa
aaaaaaab
aaaaaabb
aaaaabbb
...
bbbbbbaa
bbbbbbab
bbbbbbba
bbbbbbbb
如何显示有几种不同的组合?
最好筛选,a的个数小于等于b的个数的。如何输出?
如果不是8位 是 要求随便输入的一个数,如何输出 展开
排列里只有 0和1
然后筛选 0 <= 1 的显示在 Label1 中
例如 输入 3
则显示 011
111
101
110
谢谢,高手
a和b两个数字,每组8位,如下:
aaaaaaaa
aaaaaaab
aaaaaabb
aaaaabbb
...
bbbbbbaa
bbbbbbab
bbbbbbba
bbbbbbbb
如何显示有几种不同的组合?
最好筛选,a的个数小于等于b的个数的。如何输出?
如果不是8位 是 要求随便输入的一个数,如何输出 展开
2个回答
展开全部
窗体上添加Text1,Text2,Command1,设置Text2的MultiLine属性为瞎差 True
其中text1用于确定长度,text2用于输出,点Command开始计算
Dim A() As Byte
Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then Exit Sub
If Text1.Text <= 1 Then Exit Sub
Text2.Text = ""
Dim Rows As Long, I As Integer, J As Integer
For I = 0 To Text1.Text
Rows = Rows + C(Text1.Text, I)
Next
ReDim A(1 To Rows, 1 To Text1.Text)
J = 1
For I = 0 To Text1.Text
J = FillA(J, I, 1, Text1.Text)
Next
For I = 1 To Rows
Text2.Text = Text2.Text & I & " "
For J = 1 To Text1.Text
Text2.Text = Text2.Text & A(I, J)
Next
Text2.Text = Text2.Text & Chr(13) & Chr(10)
Next
End Sub
Function FillA(StartRow As Integer, FillNum As Integer, Index As Integer, MaxNum As Integer) As Integer
'开始填充的行液型数,要填充的个数,开始填充的列数,最大列数
Dim I As Integer, J As Integer
If FillNum = 0 Then FillA = StartRow + 1: Exit Function
If Index + FillNum - 1 > MaxNum Then FillA = StartRow: Exit Function
If FillNum > 1 Then
For I = StartRow To StartRow + C(MaxNum - Index, FillNum - 1) - 1
A(I, Index) = 1
Next
J = FillA(StartRow, FillNum - 1, Index + 1, MaxNum)
FillA = FillA(J, FillNum, Index + 1, MaxNum)
Exit Function
End If
For I = Index To MaxNum
A(StartRow + I - Index, I) = 1
Next
FillA = StartRow + MaxNum - Index + 1
End Function
Function C(Num1 As Integer, Num2 As Integer) As Integer
If Num1 <= 1 Or Num2 <= 0 Or Num2 >= Num1 Then C = 1: Exit Function
Dim I As Integer, R As Long
R = 1
For I = 1 To Num2
R = R * (Num1 - I + 1)
Next
For I = 1 To Num2
R = R / I
Next
C = R
End Function
Private Sub Form_Load()
'设置Text2的MultiLine属性为闹神猜 True
Text2.Enabled = False
Text1.Text = 8
Text2.Text = ""
Command1.Caption = "计算"
End Sub
其中text1用于确定长度,text2用于输出,点Command开始计算
Dim A() As Byte
Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then Exit Sub
If Text1.Text <= 1 Then Exit Sub
Text2.Text = ""
Dim Rows As Long, I As Integer, J As Integer
For I = 0 To Text1.Text
Rows = Rows + C(Text1.Text, I)
Next
ReDim A(1 To Rows, 1 To Text1.Text)
J = 1
For I = 0 To Text1.Text
J = FillA(J, I, 1, Text1.Text)
Next
For I = 1 To Rows
Text2.Text = Text2.Text & I & " "
For J = 1 To Text1.Text
Text2.Text = Text2.Text & A(I, J)
Next
Text2.Text = Text2.Text & Chr(13) & Chr(10)
Next
End Sub
Function FillA(StartRow As Integer, FillNum As Integer, Index As Integer, MaxNum As Integer) As Integer
'开始填充的行液型数,要填充的个数,开始填充的列数,最大列数
Dim I As Integer, J As Integer
If FillNum = 0 Then FillA = StartRow + 1: Exit Function
If Index + FillNum - 1 > MaxNum Then FillA = StartRow: Exit Function
If FillNum > 1 Then
For I = StartRow To StartRow + C(MaxNum - Index, FillNum - 1) - 1
A(I, Index) = 1
Next
J = FillA(StartRow, FillNum - 1, Index + 1, MaxNum)
FillA = FillA(J, FillNum, Index + 1, MaxNum)
Exit Function
End If
For I = Index To MaxNum
A(StartRow + I - Index, I) = 1
Next
FillA = StartRow + MaxNum - Index + 1
End Function
Function C(Num1 As Integer, Num2 As Integer) As Integer
If Num1 <= 1 Or Num2 <= 0 Or Num2 >= Num1 Then C = 1: Exit Function
Dim I As Integer, R As Long
R = 1
For I = 1 To Num2
R = R * (Num1 - I + 1)
Next
For I = 1 To Num2
R = R / I
Next
C = R
End Function
Private Sub Form_Load()
'设置Text2的MultiLine属性为闹神猜 True
Text2.Enabled = False
Text1.Text = 8
Text2.Text = ""
Command1.Caption = "计算"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询