2012年11月20日 星期二

文數字排序

由"in.txt"讀取一串的文字或數字,將其按數字、大寫英文字母、小寫英文字母排序。

出自  程式設計隊訓練教材  NO.9 文數字排序

輸入範例:
DoYouHave1456879DollarsToBorrow
輸出範例:
1456789BDDHTYaaelloooooorrrsuvw

5 則留言:

  1. Dim strr As String
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, strr
    For i = 1 To Len(strr)
    If Val(Mid(strr, i, 1)) <> 0 Then List1.AddItem Val(Mid(strr, i, 1)) + 100000
    If Val(Mid(strr, i, 1)) = 0 Then List1.AddItem Asc(Mid(strr, i, 1)) + 100000
    Next
    For ii = 0 To Len(strr) - 1
    If (List1.List(ii) - 100000) > 9 Then Print #2, Chr(List1.List(ii) - 100000) & "";
    If (List1.List(ii) - 100000) < 10 Then Print #2, List1.List(ii) - 100000 & "";
    Next
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim n 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
    Line Input #1, w
    n = Len(w)
    For i = 1 To n
    x = Mid(w, i, 1)
    x = Asc(x) + 200
    List1.AddItem x
    Next
    For i = 0 To n - 1
    x = List1.List(i)
    e = e & Chr(x - 200)
    Next
    Print #2, e
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. 作者已經移除這則留言。

    回覆刪除
  4. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x
    For i = 1 To Len(x)
    t = Asc(Mid(x, i, 1))
    m = t + 100
    List1.AddItem m
    Next
    For i = 0 To Len(x) - 1
    z = z & Chr(List1.List(i) - 100)
    Next
    Print #2, z
    Close
    Close
    End
    End Sub

    ----------------------------------------------
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x
    For i = 1 To Len(x)
    t = Asc(Mid(x, i, 1))
    Select Case t
    Case 48 To 57
    List1.AddItem Chr(t)
    Case 65 To 90
    List2.AddItem Chr(t)
    Case 97 To 122
    List3.AddItem Chr(t)
    End Select
    Next
    For k = 0 To List1.ListCount - 1
    Print #2, List1.List(k);
    Next
    For k = 0 To List2.ListCount - 1
    Print #2, List2.List(k);
    Next
    For k = 0 To List3.ListCount - 1
    Print #2, List3.List(k);
    Next
    Close
    Close
    End
    End Sub

    回覆刪除