在网上找的九宫图示例都是用VC编的,请教各位大侠,有VB的九宫编程示例,或有flash的as编程示例吗

解决方案 »

  1.   

    这个题目算法复杂度是O(N)
    比如N=9,25,49~
      

  2.   

        Const XX = 9
        Const YY = 9
        Dim matrix(XX, YY) As Integer
        Dim i      As Long
        Dim x      As Long
        Dim y      As Long
        Dim tx     As Long
        Dim ty     As Long
        Dim index  As Long
        
        index = 1
        x = XX - 1
        y = (YY + 1) / 2 - 1
        
        For i = 0 To XX * YY
            matrix(i / XX, i Mod YY) = 0
        Next i
        
        For i = 1 To XX * YY
            matrix(x, y) = i
            tx = (x + 1) Mod XX
            ty = (y + 1) Mod YY
            If matrix(tx, ty) <> 0 Then
               If x = 0 Then
                  x = XX
               Else
                  x = x - 1
               End If
            Else
               x = tx
               y = ty
            End If
        Next i
        
        Dim str1    As String
        For x = 0 To XX - 1
            str1 = ""
            For y = 0 To YY - 1
                str1 = str1 + Str(matrix(x, y)) + "  "
            Next y
            
            Debug.Print str1
        Next x