Public Class Form1
Dim r1Str = ""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fileContents As String
fileContents = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Test8.txt")
Dim recArray() = Split(fileContents, vbNewLine)
For k = 0 To recArray.Length - 1
proc_one_rec(recArray, k)
Next
'MsgBox(r1Str)
My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\result8.txt", r1Str, False)
End
End Sub
Sub proc_one_rec(ByVal recArray, ByVal k)
Dim s = recArray(k)
Dim n = Math.Ceiling(s.length ^ 0.5)
Dim a(n + 1, n + 1) As String
For i = 0 To n + 1
For j = 0 To n + 1
If i = 0 Or i = n + 1 Or j = 0 Or j = n + 1 Then
a(i, j) = "X"
Else
a(i, j) = "#"
End If
Next
Next
Dim sindex = 1
Dim x = 1
Dim y = 1
Dim dx = 1
Dim dy = 0
Dim dirN = 0
Dim prex = x
Dim prey = y
While sindex <= s.length
'非空位處理,退回原位置,轉向,前進至下一位置
If a(x, y) <> "#" Then
x = prex
y = prey
dirN = dirN + 1
dirN = dirN Mod 4
If dirN = 0 Then
dx = 1
dy = 0
End If
If dirN = 1 Then
dx = 0
dy = 1
End If
If dirN = 2 Then
dx = -1
dy = 0
End If
If dirN = 3 Then
dx = 0
dy = -1
End If
x = x + dx
y = y + dy
End If
a(x, y) = Mid(s, sindex, 1)
'保留上次位置
prex = x
prey = y
'取得下次位置,下一個字元
x = x + dx
y = y + dy
sindex = sindex + 1
End While
'一次結果
Dim rStr = ""
For y = 1 To n
For x = 1 To n
rStr = rStr + a(x, y)
Next
rStr = rStr & vbNewLine
Next
rStr = Replace(rStr, "#", " ")
r1Str = r1Str & rStr & vbNewLine
End Sub
End Class
標籤雲
visual basic 2008
(157)
訊息分享
(111)
Visual Studio 2008
(64)
wpf
(37)
每日一句
(35)
cpp
(30)
python
(26)
Silverlight
(22)
C++
(18)
Network Security
(15)
全國技藝競竇
(14)
好文分享
(11)
.Net
(10)
Blogger
(10)
名詞解釋
(10)
研討會
(10)
Excel
(9)
書籍介紹
(9)
每日一小品
(9)
電腦黑白講
(8)
Visual Studio 201X
(7)
分享
(7)
網頁設計
(7)
CSS
(5)
Algorithm
(4)
Network
(3)
PHP
(3)
Access
(2)
SA
(2)
VB.Net
(2)
VBA
(2)
WireShark
(2)
Word
(2)
php html
(2)
其他好東東
(2)
分類整理
(2)
Asp.Net
(1)
Batch
(1)
Blockly
(1)
IT News
(1)
OpenAI
(1)
SE
(1)
W7
(1)
Writer
(1)
app inv2
(1)
dfs
(1)
vex vr sample
(1)
影像處理練習
(1)
黑白講
(1)
2009年6月25日 星期四
97技藝競賽第8題 -- VB2008版
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言