說明:請寫一個程式,老師可以輸入全班的「程式設計」成績,並依總分來排名次,學生人數不超過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
Private Sub Form_Load()
回覆刪除Me.Hide
Dim n(50), g(50), f(50)
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
a = 0
Do While Not EOF(1)
Input #1, y, x
a = a + 1
n(a) = y
g(a) = x
Loop
Print #2, "學號 程式設計 名次"
Print #2,
For i = 1 To a
f(i) = 1
For j = 1 To a
If g(i) < g(j) Then f(i) = f(i) + 1
Next
Print #2, i & " " & g(i) & " " & f(i)
Next
Close
Close
End
End Sub
小冰好,
回覆刪除程式正確。
Dim n(), g(), r() As Integer
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
a = 1
Do While Not EOF(1)
ReDim Preserve n(a), g(a), r(a)
Input #1, x, y
n(a) = Val(x)
g(a) = Val(y)
a = a + 1
Loop
For i = 1 To UBound(n())
r(i) = 1
For j = 1 To UBound(n())
If g(i) < g(j) Then r(i) = r(i) + 1
Next j
Next i
Print #2, "學號 程式設計 名次"
For i = 1 To UBound(r())
Print #2, n(i) & Space(7) & g(i) & Space(7) & r(i)
Next i
Close #2
Close #1
End
End Sub