English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

請問如何寫出一個"列印出各字元即出現次數"
然後出現次數由高到低排列
範例"
   輸入"yahoo com tw

輸出為: "o"=3;" "=2;"y"=1;"a"=1;"h"=1;"c"=1;"m"=1;"t"=1;"w"=1

知道的可以告訴我媽...拜託囉!

2007-01-13 05:43:07 · 1 個解答 · 發問者 ﹍ ﹢ Mix ≠ 默默 ★” 1 in 電腦與網際網路 程式設計

1 個解答


'版本VB6.0:不區分大小寫
Private Sub Command1_Click()
Dim A$, K$, S$(), N%(), I%, J%

A = InputBox("輸入字串", , "yahoo com tw")
If A = "" Then Exit Sub
T = " "
Do
K = Left$(A, 1)
ReDim Preserve S(J), N(J)
S(J) = K: N(J) = UBound(Split(UCase(A), UCase(K)))
J = J + 1: T = T & K & " "
A = Replace(A, K, "", , , vbTextCompare)
Loop Until A = ""
For I = 0 To UBound(N) - 1
For J = I To UBound(N)
If N(I) < N(J) Then
T = N(I): N(I) = N(J): N(J) = T
T = S(I): S(I) = S(J): S(J) = T
ElseIf N(I) = N(J) Then
If S(I) > S(J) Then T = S(I): S(I) = S(J): S(J) = T
End If
Next
Next
For I = 0 To UBound(N)
Print """"; S(I); """"; " = "; N(I); ""
Next
End Sub

2007-01-13 09:24:06 · answer #1 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers