有点小瑕疵 lowxiong 原数据:6,3,11,12,4,可以组成顺子。5,|5,7,| 这个是出来的结果 应该为 2,5,|5,7,| 这个挺难的
有时候还出现 原数据:6,3,11,12,4,可以组成顺子。 没有可组成数字输出
Private Sub Command1_Click()
Dim a As String, b() As String, c() As String, d As String, i As Integer, j As Integer, s As Integer
Randomize
s = Int(Rnd * 3) + 5 '随机数据个数
a = ""
j = Int(Rnd * 13) + 1
For i = 1 To s
While InStr(a, j) > 0
j = Int(Rnd * 13) + 1
Wend
a = a & j & ","
Next
'上述代码产生随机数据在a里
'a = "10,2,5,3,9," '该数据实验用
a = "6,3,11,12,4,"
Text1 = "原数据:" & Left(a, Len(a) - 1)
d = ""
PermComb a, d
If d <> "" Then
Text1 = Text1 & ",可以组成顺子。"
If s < 7 Then
b = Split(d, "|")
For i = 0 To UBound(b) - 1
c = Split(b(i), ",")
d = ""
For j = 0 To 6
If InStr(a, c(j) & ",") = 0 Then d = d & c(j) & ","
Next
Text1.Text = Text1.Text & d & "|"
Next
End If
Else
Text1 = Text1 & ",无法组成顺子。"
End If
End Sub
[
本帖最后由 softshl1 于 2014-5-20 09:50 编辑 ]