2012年11月20日 星期二

5/21程式小考_4th



 輸入MN兩陣列,其中M為姓名N為成績,請按照成績高低排序並輸出。
(若發現成績相同,則照字母順序排列)
輸入一: Ezreal
             Ashe
             Leona
             Lux
輸入二: 80
                     20
                     75
                     89
  輸出範例:  
Lux 89
Ezreal 80
Leona 75
Ashe 20

2 則留言:

  1. Dim num(10) As Integer
    Dim strr(10) As String
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in1.txt" For Input As #1
    Open App.Path & "\in2.txt" For Input As #2
    Open App.Path & "\out.txt" For Output As #3
    k = 1
    Do
    Input #1, strr(k)
    Input #2, num(k)
    k = k + 1
    Loop Until EOF(1)
    For i = 1 To k - 1
    List1.AddItem num(i) - 10000
    Next
    For ii = 0 To List1.ListCount - 1
    For iii = 1 To k - 1
    If Val(List1.List(ii)) + 10000 = num(iii) Then Print #3, strr(iii) & " " & num(iii)
    Next
    Next
    Close #3
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim a() As String
    Dim b() 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
    Open App.Path & "\in2.txt" For Input As #3
    r = 1
    Do While Not EOF(1)
    Input #1, x
    Input #3, y
    ReDim Preserve a(r), b(r)
    a(r) = x
    b(r) = y
    r = r + 1
    Loop
    For i = 1 To UBound(b)
    For j = i To UBound(b)
    If b(i) < b(j) Then
    z = b(i): h = a(i)
    b(i) = b(j): a(i) = a(j)
    b(j) = z: a(j) = h
    ElseIf b(i) = b(j) Then
    If Left(a(i), 1) > Left(a(j), 1) Then
    h = a(i)
    a(i) = a(j)
    a(j) = h
    End If
    End If
    Next j
    Next i
    For i = 1 To UBound(a)
    Print #2, a(i); b(i)
    Next i
    Close #3
    Close #2
    Close #1
    End
    End Sub

    回覆刪除