- '规则不够那就凑,,,
- Option Explicit
- Sub test()
- Dim s, i, t, flag As Boolean
- s = Split("A□□B□□C□□D□□E□□F", "□")
- Randomize
- For i = 0 To UBound(s)
- If Len(s(i)) = 0 Then
- s(i) = IIf(Rnd < 0.5, "+", "* ")
- End If
- Next
- s = Join(s, vbNullString) & "* "
- If InStr(s, "*") Then
- Do
- flag = False
- t = Split(s, "* ")
- For i = 1 To UBound(t) - 1
- If InStr(t(i), "+") > 0 And InStr(t(i), ")") = 0 Then
- t(i) = "(" & t(i) & ")"
- s = Join(t, "* ")
- flag = True: Exit For
- End If
- Next
- Loop Until Not flag
- End If
- s = "*" & Replace(s, Space(1), vbNullString)
- s = left(s, Len(s) - 1)
- Debug.Print s & vbNewLine & String(20, "=")
- End Sub
复制代码
|