REM 103年模擬 P21:編碼處理-摩斯電碼
Private Sub Form1_Load( . . .) Handles MyBase.Load
REM tbl陣列: 第1列 A~G , 第2列 H~M , 第3列 N~T
, 第4列 U~Z
Dim tbl() = {".-", "-...", "-.-.",
"-..", ".", "..-.", "--.",
"....",
"..", ".---", "-.-", ".-..",
"--",
"-.",
"---", ".--.", "--.-", ".-.",
"...", "-",
"..-",
"...-", ".--", "-..-", "-.--",
"--.."}
FileOpen(1, "in1.txt", OpenMode.Input)
FileOpen(2, "in2.txt",
OpenMode.Input)
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 2
Dim n As Integer = LineInput(fn)
For i = 1 To n
Dim d() =
LineInput(fn).Split(" ")
For j = 0 To UBound(d)
Dim k = Array.IndexOf(tbl,
d(j)) '由tbl找符合d(j)的字串,傳回索引
Print(3, Chr(k + 65)) '索引為 0A,1B,...,24Y,25Z
:
加上65即為 65~90
Next
PrintLine(3)
Next
PrintLine(3)
Next
End
End Sub
In1.txt
5
... --- ...
-.-- --- ..-
.- -. -..
..
.... . .-.. .--.
In2.txt
3
.--. .-. --- --. .-. .- --
...- .. .-. - ..- .- .-.. -... .- ... ..
-.-.
--. --- --- --. .-.. .
Out.txt
SOS
YOU
AND
I
HELP
PROGRAM
VIRTUALBASIC
GOOGLE
0 意見:
張貼留言