輸入一變數N,再輸入一個含有N個數的集合A,然後輸出所有這個人A集合的子集合。
範例輸入:
3
範例輸出:
{ 1 }
{ 2 }
{ 3 }
{ 1 , 2 }
{ 1 , 3 }
{ 2 , 3 }
{ 1 , 2 , 3 }
{ } <--空集合
2006-10-27 06:34:59 · 1 個解答 · 發問者 小均 2 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click() Dim I As Integer, S As String, A() As String Do N = Abs(Int(Val(InputBox("請輸入正整數", , 3)))) Loop Until N ReDim A(N - 1) For I = 0 To N - 1 A(I) = I + 1 Next Cls Call Assembler(-1, S, A)End SubSub Assembler(ByVal D As Integer, ByRef S As String, ByRef A() As String) Dim I As Integer For I = D + 1 To UBound(A) S = S & A(I) & "," Print "{"; Left$(S, Len(S) - 1); "}" Call Assembler(I, S, A) S = Left$(S, InStrRev(S, ",", Len(S) - 1)) NextEnd Sub
2006-10-27 08:12:36 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋