VB语言高手实现不定位数组限定
VB语言高手实现不定位数组限定第一问:简化问题将M选N组合硬性规定为10选6组,第一问做好从1,2,3,4,5,6,7,8,9,10这10个数字中任取6个组合输出,第二问...
VB语言高手实现不定位数组限定
第一问:简化问题将M选N组合硬性规定为10选6组,第一问做好
从1,2,3,4,5,6,7,8,9,10这10个数字中任取6个组合输出,第二问不会请高手完成
第二问:将第一问数据过滤输出不定位只要每行有5个相同数字就过滤,只保留一行
例如结果
1-2-3-4-5-6
1-2-3-4-5-7
1-2-3-4-5-8
只需保留任意一行
1-2-3-4-5-6
Private Sub Command1_Click()
Dim m As Integer, n As Integer, i As Integer
Dim k(), t As String
m = Val(InputBox("请输入M值", 10))
n = Val(InputBox("请输入N值", 6))
ReDim k(1 To n)
Do
For i = n To 1 Step -1
k(i) = k(i) + 1
If k(i) > m Then
If i > 1 Then k(i) = k(i - 1) + 1
Else
Exit For
End If
Next
If i > 0 Then
If chkarr(k, t) Then
If t <> "" Then t = t & vbCrLf
t = t & Join(k, "-")
End If
Else
Exit Do
End If
Loop
MsgBox t
End Sub 展开
第一问:简化问题将M选N组合硬性规定为10选6组,第一问做好
从1,2,3,4,5,6,7,8,9,10这10个数字中任取6个组合输出,第二问不会请高手完成
第二问:将第一问数据过滤输出不定位只要每行有5个相同数字就过滤,只保留一行
例如结果
1-2-3-4-5-6
1-2-3-4-5-7
1-2-3-4-5-8
只需保留任意一行
1-2-3-4-5-6
Private Sub Command1_Click()
Dim m As Integer, n As Integer, i As Integer
Dim k(), t As String
m = Val(InputBox("请输入M值", 10))
n = Val(InputBox("请输入N值", 6))
ReDim k(1 To n)
Do
For i = n To 1 Step -1
k(i) = k(i) + 1
If k(i) > m Then
If i > 1 Then k(i) = k(i - 1) + 1
Else
Exit For
End If
Next
If i > 0 Then
If chkarr(k, t) Then
If t <> "" Then t = t & vbCrLf
t = t & Join(k, "-")
End If
Else
Exit Do
End If
Loop
MsgBox t
End Sub 展开
展开全部
Dim ball(33)
Dim stri As String
Private Sub Form_Load()
'窗体上有下列控件
'两个按钮 command1,command2
Text1.Text = "1-2-3-4-5-6"
Text2.Text = 15
Text3.Text = 6
Text4.Text = 5
RText1.Text = "" '富文本框,普通文件框放不下这么多数据 多行
RText2.Text = "" 'microsoft rich textbox control 多行
End Sub
Sub zuhe(m, n, x, y)
If x > n Then
For i = 1 To n - 1
stri = stri & ball(i) & "-"
Next i
stri = stri & ball(i) & vbCrLf
Exit Sub
End If
For i = y To m
ball(x) = i
zuhe m, n, x + 1, i + 1
Next i
End Sub
Private Sub Command1_Click()
'从text2获取M的值 如15
'从text3获取N的值 如6
'在Rtext1中显示从M选N的所有组合
stri = ""
m = Val(Text2.Text)
n = Val(Text3.Text)
zuhe m, n, 1, 1
RText1.Text = stri
End Sub
Private Sub Command2_Click()
Dim a() As String
Dim b(33)
'从text1获取匹配模板 如1-2-3-4-5-6
'从text4获取要求匹配的个数 如5
'从Rtext1中查找可以匹配成功的组合,把组合显示在Rtext2中
a = Split(RText1.Text, vbCrLf)
For i = 1 To 33: b(i) = 0: Next
c = Split(Text1.Text, "-")
For i = 0 To UBound(c)
b(c(i)) = 1
Next i
stri = ""
For i = 0 To UBound(a)
total = 0
c = Split(a(i), "-")
For j = 0 To UBound(c)
total = total + b(c(j))
Next j
If total = Val(Text4.Text) Then '有text4.text个数匹配,如果查询是要或更多的,条件改为>=
stri = stri & a(i) & vbCrLf
End If
Next i
RText2.Text = stri
End Sub
Dim stri As String
Private Sub Form_Load()
'窗体上有下列控件
'两个按钮 command1,command2
Text1.Text = "1-2-3-4-5-6"
Text2.Text = 15
Text3.Text = 6
Text4.Text = 5
RText1.Text = "" '富文本框,普通文件框放不下这么多数据 多行
RText2.Text = "" 'microsoft rich textbox control 多行
End Sub
Sub zuhe(m, n, x, y)
If x > n Then
For i = 1 To n - 1
stri = stri & ball(i) & "-"
Next i
stri = stri & ball(i) & vbCrLf
Exit Sub
End If
For i = y To m
ball(x) = i
zuhe m, n, x + 1, i + 1
Next i
End Sub
Private Sub Command1_Click()
'从text2获取M的值 如15
'从text3获取N的值 如6
'在Rtext1中显示从M选N的所有组合
stri = ""
m = Val(Text2.Text)
n = Val(Text3.Text)
zuhe m, n, 1, 1
RText1.Text = stri
End Sub
Private Sub Command2_Click()
Dim a() As String
Dim b(33)
'从text1获取匹配模板 如1-2-3-4-5-6
'从text4获取要求匹配的个数 如5
'从Rtext1中查找可以匹配成功的组合,把组合显示在Rtext2中
a = Split(RText1.Text, vbCrLf)
For i = 1 To 33: b(i) = 0: Next
c = Split(Text1.Text, "-")
For i = 0 To UBound(c)
b(c(i)) = 1
Next i
stri = ""
For i = 0 To UBound(a)
total = 0
c = Split(a(i), "-")
For j = 0 To UBound(c)
total = total + b(c(j))
Next j
If total = Val(Text4.Text) Then '有text4.text个数匹配,如果查询是要或更多的,条件改为>=
stri = stri & a(i) & vbCrLf
End If
Next i
RText2.Text = stri
End Sub
追问
好乱,你传过VB源文件过来,好吗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询