4/10(一)測驗題單 (題目名加上連結的表示範例完成)
假設由文字方塊輸入,呼叫 Function MyPxx( S As String ) As String後傳回要輸出的字串
以下只有M5P11附主程式部份,其餘類似
以下只有M5P11附主程式部份,其餘類似
105模擬
|
M5P11
| |
105模擬
|
M5P22
| |
105模擬
|
M5P42
| |
105正式
|
F5P11
| |
105正式
|
F5P12
| |
105正式
|
F5P21
| |
105正式
|
F5P22
| |
104模擬
|
M4P12
| |
104模擬
|
M4P21
| |
104模擬
|
M4P42
| |
104正式
|
F4P11
| |
104正式
|
F4P22
| |
104正式
|
F4P31
| |
103模擬
|
M3P11
| |
103模擬
|
M3P12
| |
103模擬
|
M3P21
| |
103模擬
|
M3P22
|
Function M3P11(ByVal s As String) As String
'傳入一個 字串s 轉為整數 x ,判斷是否為質數,是傳回字串Y,否傳回N
Dim x As Integer = s
If x < 2 Then Return "N"
For k = 2 To Math.Sqrt(x)
If x Mod k = 0 Then Return "N"
Next
Return "Y"
End Function
=====輸入範例
2
11
4
127
523
31
19
2047
9751
65521
=====輸出範例
Y
Y
N
Y
Y
Y
Y
N
N
Y
===============
Function M3P12(ByVal s As String) As String
Dim dt() = s.Split(",") '讀一列依 「,」分成6個字串Dim a As Integer = dt(0), b As Integer = dt(1)
Dim c As Integer = dt(2), d As Integer = dt(3)
Dim e As Integer = dt(4), f As Integer = dt(5)
'rem 聯立式(1)ax+by=c ,(1)式*e - (2)式*b 得(ae-db)x = (ce-fb)
'rem 聯立式(2)dx+ey=f ,(1)式*d - (2)式*a 得(bd-ea)y = (cd-fa)
Dim x As Integer = (c * e - f * b) / (a * e - d * b)
Dim y As Integer = (c * d - f * a) / (b * d - e * a)
Return x & "," & y
End Function
=====輸入範例
0,2,20,1,0,10
9,5,17,33,6,-24
9,5,17,33,6,-24
2,5,2,1,2,7
2,5,95,-10,2,-16
=====輸出範例
10,10
-2,7
31,-12
5,17
-2,7
31,-12
5,17
===============
Function M3P22(ByVal s As String) As String
M3P22=""
For j = 1 To s.Length '字串長度
Dim c As Char = Mid(s, j, 1)
If c >= "X" Then
M3P22 &= Chr(Asc(c) - 23)
Else
M3P22 &= Chr(Asc(c) + 3)
End If
Next
For j = 1 To s.Length '字串長度
Dim c As Char = Mid(s, j, 1)
If c >= "X" Then
M3P22 &= Chr(Asc(c) - 23)
Else
M3P22 &= Chr(Asc(c) + 3)
End If
Next
End Function
=====輸入範例
WIKIPEDIA
YOU
B
C
EF
XYZA
TEST
YOU
B
C
EF
XYZA
TEST
=====輸出範例
ZLNLSHGLD
BRX
E
F
HI
ABCD
WHVW
BRX
E
F
HI
ABCD
WHVW
===============