2010年11月5日 星期五

二進位列舉應用

'二進位列舉應用
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim str1 = ""
        Dim str2 = ""
        Dim a() = {0, 1}
        Dim e1, e2, e3, e4
        For Each e4 In a
            For Each e3 In a
                For Each e2 In a
                    For Each e1 In a
                        str1 = str1 & e4 & e3 & e2 & e1 & vbNewLine
                        str2 = str2 & IIf(e4 = 1, "(肉)", "肉") & IIf(e3 = 1, "(菜)", "菜") & IIf(e2 = 1, "(蛋)", "蛋") & IIf(e1 = 1, "(果)", "果") & vbNewLine
                    Next
                Next
            Next
        Next
        MsgBox(str1 & vbNewLine & str2)
        End
    End Sub
End Class

沒有留言: