參考程式碼:
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) '本題1個檔
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 1 '本題1個檔
If fn = 2 Then PrintLine(3)
Dim t As Short = LineInput(fn)
For k = 1 To t ' t 組資料
Dim nr() = LineInput(fn).Split(" ")
Dim n As Integer = nr(0), r As Integer = nr(1)
Dim los(n) As Boolean ' 最多20人
Dim nam(n) As String '對戰者姓名總表
Dim ncnt As Integer = 0 '計數
Dim a, b As String '對戰者姓名
Dim ai, bi As Integer '對戰者編號 1~n
For i = 1 To r 'r 次 對戰
Dim ab() = LineInput(fn).Split(" ")
a = ab(0) : b = ab(1)
ai = Array.IndexOf(nam, a)
If (ai < 0) Then
ncnt += 1
nam(ncnt) = a
ai = ncnt
End If
bi = Array.IndexOf(nam, b)
If (bi < 0) Then
ncnt += 1
nam(ncnt) = b
bi = ncnt
End If
' PrintLine(3, ai & ":" & a & "," & bi & ":" & b) '列出編號參考用
los(bi) = True '輸的設為 true
Next
' 因為 王者 會贏其他所有的人,不會輸,印出唯一沒輸過的
For i = 1 To n
If Not los(i) Then PrintLine(3, nam(i))
Next
Next k
Next fn
End
End Sub
in1.txt
3
3 3
tpa azf
tpa abc
azf abc
5 11
tpa azf
azf abc
tpa abc
abc xyz
tpa abcde
xyz abc
azf abcde
azf xyz
abc azf
tpa xyz
azf abcde
5 12
mmm bbb
bbb ccc
mmm ccc
ddd mmm
mmm eee
ddd ccc
ddd bbb
bbb mmm
ddd eee
bbb eee
mmm bbb
bbb ccc
tpa
tpa
ddd
0 意見:
張貼留言