說明:請寫一個程式,老師可以輸入全班的「程式設計」成績,並依總分來排名次,學生人數不超過50人。
輸入格式:依學號輸入學科「程式設計」的成績1-50比。 學號與成績已1個空白隔開
輸出格式:輸入之資料排名表,依學號的順序輸出,同分者名次必須相同,第二行起為學生學號、成績與名次,各以七個空白隔開。
輸入範例:
1 56
2 88
3 44
4 44
5 22
輸出:
學號 程式設計 名次
1 56 2
2 88 1
3 44 3
4 44 3
Dim num(99), grad(99), mycount As Integer
回覆刪除Dim repeat As Boolean
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
mycount = 0
Do
mycount = mycount + 1
Input #1, num(mycount), grad(mycount)
For i = 1 To mycount - 1
If grad(mycount) = grad(i) Then repeat = True
Next
If repeat = False Then List1.AddItem grad(mycount) - 100000
repeat = False
Loop Until EOF(1)
Print #2, "學號 程式設計 名次"
For i = 1 To mycount
For ii = 0 To List1.ListCount
If grad(i) = (List1.List(ii) + 100000) Then Print #2, num(i) & " " & grad(i) & " " & ii + 1: Exit For
Next
Next
Close #2
Close #1
End
End Sub