English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

輸入一變數N , 再輸入N 個數字成為一個含有N 個數的集合A , 然後輸出所有這個A 集合的子集合。
Ex: N=3, A { 1, 2, 3 }
ANS: { 1 }
{ 2 }
{ 3 }
{ 1, 2 }
{ 1, 3 }
{ 2, 3 }
{ 1, 2, 3 }
{ } <--- 空集合

2006-10-21 02:17:32 · 1 個解答 · 發問者 公路殺手....小古是也 1 in 電腦與網際網路 程式設計

1 個解答

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-21 20:24:20 · answer #1 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers