- 生肖
- 蛇
- 性别
- 男
- 积分
- 208
- 积分
- 216
- 精华
- 0
- 阅读权限
- 30
- 注册时间
- 2012-4-28
- 最后登录
- 2012-6-1
- 帖子
- 30
- 生肖
- 蛇
- 性别
- 男
|
本帖最后由 fieldmax 于 2012-4-28 22:17 编辑
- Public Enum DirectionEnum
- ToRight = 0
- ToDown = 1
- End Enum
- Sub zMatrix(X As Long, Y As Long, Optional Direction As DirectionEnum = 0)
- 蛇形矩阵
- Dim iX As Long
- Dim iY As Long
- Dim n As Long
- Dim DT As DirectionEnum
- ReDim mat(1 To X, 1 To Y) As Long
- DT = Direction
- iX = 1
- iY = 1
- n = 1
- mat(1, 1) = 1
- Do While n < X * Y
- n = n + 1
- If DT = 0 And (iY = 1 Or iX = X) Then
- If iX < X Then
- iX = iX + 1
- Else
- iY = iY + 1
- End If
- DT = 1
- ElseIf DT = 1 And (iX = 1 Or iY = Y) Then
- If iY < Y Then
- iY = iY + 1
- Else
- iX = iX + 1
- End If
- DT = 0
- ElseIf DT = 0 Then
- iX = iX + 1
- iY = iY - 1
- ElseIf DT = 1 Then
- iX = iX - 1
- iY = iY + 1
- End If
- mat(iX, iY) = n
- Loop
- '打印部分
- Dim TempTx As String
- For iY = 1 To Y
- For iX = 1 To X
- If mat(iX, iY) >= 1000 Then
- TempTx = TempTx & " " & mat(iX, iY)
- ElseIf mat(iX, iY) >= 100 Then
- TempTx = TempTx & " " & mat(iX, iY)
- ElseIf mat(iX, iY) >= 10 Then
- TempTx = TempTx & " " & mat(iX, iY)
- Else
- TempTx = TempTx & " " & mat(iX, iY)
- End If
- Next
- Print TempTx & vbCrLf
- TempTx = ""
- Next
- End Sub
- Sub yhSj(C As Integer)
- '杨晖三角
- ReDim Tx(C, C) As Long
- Dim TempTe As String
- Dim iX As Integer
- Dim iY As Integer
- Tx(0, 0) = 1
- For iY = 1 To C
- For iX = 1 To iY
- Tx(iX, iY) = Tx(iX - 1, iY - 1) + Tx(iX, iY - 1)
- If Tx(iX, iY) >= 100 Then
- TempTx = TempTx & Tx(iX, iY) & " "
- ElseIf Tx(iX, iY) >= 10 Then
- TempTx = TempTx & Tx(iX, iY) & " "
- Else
- TempTx = TempTx & Tx(iX, iY) & " "
- End If
- Next
- Print TempTx
- TempTx = ""
- Next
- End Sub
复制代码 |
|