2012年8月12日 星期日

國際資訊奧林匹亞獎牌計算

參加國際資訊奧林匹亞(IOI)競賽者大約有一半的選手可以獲得獎牌。In_d.txt即為被評為可以獲獎的名單(第1欄為國家代碼,第2欄為選手姓名,第3欄為其成績),在此名單中,金、銀、銅牌的分配約為1:2:3。試寫一程式依得分高任分配獎牌。輸出包括四部分: 
由高至低排序,並將得獎類別寫在分數旁[G(金)、S(銀)、B(銅)]( 如輸出範例1)。 
獎牌分配,即獲得金、銀、銅牌的個數 (如輸出範例2)。 
得獎牌最多的國家,寫出國家代碼及獎牌 (不分類別) 數 (如輸出範例3)。 
所有得獎者分數之平均數、最高分、最低分及全距 (即最高分與最低分的差距)(如輸出範例4)。

輸入範例(in_d.txt):
RSA Bruce Merry 333
HUN Balazs Racz 250
UKR Oleksandr lotko 230
ROM Bogdan Dumitru 360
VIE Nguyen N. Huy 430
SUI Peter Kaufmann 266
CRO Frane Saric 268
ROM Radu A. Stefan 150
BLR Ivan Miatselski 226
AUS Peter Hawkins 225
SVK Jan Senko 210
BUL Svetlin Nakov 208

輸出範例1
VIE Nguyen N. Huy 430 G
ROM Bogdan Dumitru 360 G
RSA Bruce Merr 333 S
CRO Frane Saric 268 S
SUI Peter Kaufmann 266 S
HUN Balazs Racz 250 S
UKR Oleksandr lotko 230 B
BLR Ivan Miatselski 226 B
AUS Peter Hawkins 225 B
SVK Jan Senko 210 B
BUL Svetlin Nakov 208 B
ROM Radu A. Stefan 150 B

輸出範例2
G 2
S 4
B 6

輸出範例3
ROM 2

輸出範例4
263.00 430.00 150.00 280.00

1 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Dim x(100)
    Dim y(100, 1)
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Open App.Path & "\out1.txt" For Output As #3
    Open App.Path & "\out2.txt" For Output As #4
    Open App.Path & "\out3.txt" For Output As #5
    a = 0
    Do While Not EOF(1)
    a = a + 1
    Line Input #1, x(a)
    ans = ans + Val(Right(x(a), 3))
    Loop
    For i = 1 To a
    For j = 1 To a - 1
    If Val(Right(x(j), 3)) < Val(Right(x(j + 1), 3)) Then
    b = x(j)
    x(j) = x(j + 1)
    x(j + 1) = b
    End If
    Next
    Next
    n = a / 6
    For i = 1 To n * 6
    y(i, 0) = Left(x(i), 3)
    Next
    Max = 0
    For i = 1 To n * 6
    If i <= n Then Print #2, x(i) & " G"
    If n < i And i <= n * 3 Then Print #2, x(i) & " S"
    If n * 3 < i And i <= n * 6 Then Print #2, x(i) & " B"
    Next
    For i = 1 To n * 6
    For j = 1 To n * 6
    If y(i, 0) = Left(x(j), 3) Then y(i, 1) = Val(y(i, 1)) + 1
    If Max < Val(y(i, 1)) Then Max = y(i, 1): e = i
    Next
    Next
    Print #3, "G " & n
    Print #3, "S " & n * 2
    Print #3, "B " & n * 3
    Print #4, y(e, 0) & " " & Max
    Print #5, Format(ans / a, "##0.00") & " ";
    Print #5, Format(Right(x(1), 3), "##0.00") & " ";
    Print #5, Format(Right(x(a), 3), "##0.00") & " ";
    Print #5, Format(Val(Right(x(1), 3) - Val(Right(x(a), 3))), "##0.00");
    Close
    Close
    Close
    Close
    Close
    End
    End Sub

    回覆刪除