105正-F5P11 計算字數 ✔(上一篇已傳)
105正-F5P12 摩斯電碼 ✔
105正-F4P21 網段ID ✔
105模-M5P11 質數 ✔(上一篇已傳)
105模-M5P22 行、字數、字元數 ✔(上一篇已傳)
105模-M5P41 尋找對稱字串
105模-M5P42 十進制轉二進制 ✔(上一篇已傳)
105模-M5P21 前綴字串and後綴字串
補充大數 N! (0<N<1000) ✔(上一篇已傳)
內建函式整理: ======================
1.Array.IndexOf(ms,m):內建陣列函式,由陣列ms中找m,傳回其索引值{0~},找不到-1 例 ms={5,4,3,2} 則Array.IndexOf(ms,3) 傳回 2
2.mid(s,m,n):內建字串函數,由字串 s 的第m個字起取n個字{包含第m個字},不足n取至末 例 s="9876543" 則mid(s,2,3) 傳回 "876"
3.mid(s,m):內建字串函數,由字串 s 的第m個字起取至末
例 s="9876543" 則mid(s,6) 傳回 "43"
======================================
105正-F5P12: 摩斯電碼 ================================
' 本題 摩斯字串 對照 0~4 、 5~9
' 以 Array.IndexOf( )函數查找即可
Dim ms() As String = {"-----", ".----", "..---", "...--", "....-",
".....", "-....", "--...", "---..", "----."}
Function P12(ByVal s As String) As String
P12 = ""
ttrim(s, " ", " ") '去首尾空白及中間2個以上空白換成1個
Dim dat() = s.Split(" ")
For Each m In dat
P12 &= Array.IndexOf(ms, m)
Next
End Function
Sub ttrim(ByRef s As String, ByVal a As String, ByVal b As String)
s = Trim(s)
Do While (InStr(s, " ") > 0)
s = s.Replace(" ", " ")
Loop
End Sub
105正-F4P21: 網段ID ================================
Function P21(ByVal s As String) As StringDim a, b As Integer
Dim p As Integer = InStr(s, "/")
Dim sa() = Mid(s, 1, p - 1).Split(".")
Dim sb() = Mid(s, p + 1).Split(".")
P21 = ""
For j = 0 To 3
a = sa(j)
b = sb(j)
If j > 0 Then P21 &= "."
P21 &= (a And b)
Next
0 意見:
張貼留言