M2P11 : 102模P11 字串中的阿拉伯數字
http://rs-vb.blogspot.tw/2016/10/z2am2p11.html
M3P11 : 103模P11 判斷是否為質數
http://rs-vb.blogspot.tw/2016/10/z2am3p11.html
M3P12 : 103模P12 解二元一次方程式
http://rs-vb.blogspot.tw/2016/10/z2am3p12.html
M2P12 :102模P12樂透
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FileOpen(1, "in1.txt", OpenMode.Input)
FileOpen(2, "in2.txt", OpenMode.Input)
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 2
If fn = 2 Then PrintLine(3)
Dim line1() = LineInput(fn).Split(":")
Dim n As Integer = line1(0) ' 第1行的 :前 即第1個數字 n
Dim a() = line1(1).Split(",") ' : 號之後的五個數字為抽出的號碼
Dim an(4), bn(4) As Integer
For j = 0 To 4
an(j) = a(j)
Next
Array.Sort(an)
For i = 1 To n
Dim line = LineInput(fn)
PrintLine(3, M2P12(an, line))
Next
Next
End
End Sub
Function M2P12(ByVal an() As Integer, ByVal s As String) As String
Dim b() = s.Split(",")
Dim bn(4) As Integer
For j = 0 To 4
bn(j) = b(j)
Next
Array.Sort(bn)
Dim ai = 0, bi = 0, cnt = 0
Do Until ai > 4 Or bi > 4
If an(ai) = bn(bi) Then
cnt += 1
ai += 1 : bi += 1
ElseIf an(ai) > bn(bi) Then
bi += 1
Else
ai += 1
End If
Loop
Return IIf(cnt < 2, "N", "" & cnt)
End Function
0 意見:
張貼留言