VB编程:编写程序,统计一段英文中26个字母出现的频率,并按其频率从高到低排序输出
(1)英文从.TXT文件中读出;(2)字母的统计由自己自定义子过程完成;(3)将排好寻序的字母输出到TEXT文本框里。...
(1)英文从.TXT文件中读出;
(2)字母的统计由自己自定义子过程完成;
(3)将排好寻序的字母输出到TEXT文本框里。 展开
(2)字母的统计由自己自定义子过程完成;
(3)将排好寻序的字母输出到TEXT文本框里。 展开
3个回答
展开全部
Private Sub Command1_Click()
Dim s1 As String, s2 As String, t As Integer
Dim sN(0 To 25) As Integer, ss(0 To 25) As Integer
Open "(这里写盘符+文件名.txt)" For Input As #1
Do While Not EOF(1)
Input #1, s1
s2 = s2 + s1
Loop
Close #1
Call countN(s2, sN)
For i = 0 To 25
ss(i) = i
Next i
For i = 0 To 25 - 1
For j = i + 1 To 25
If sN(i) < sN(j) Then
t = sN(i)
sN(i) = sN(j)
sN(j) = t
t = ss(i)
ss(i) = ss(j)
ss(j) = t
End If
Next
Next
Text1.Text = ""
For i = 0 To 25
Text1.Text = Text1.Text & " " & Chr(ss(i) + 65) ' & "=" & sN(i)
Next i
End Sub
Function countN(str, Arr)
Dim i, j
Dim bound
bound = UBound(Arr)
For i = 1 To Len(str)
For j = 0 To bound
If Asc(Mid(str, i, 1)) = j + 65 Or Asc(Mid(str, i, 1)) = j + 97 Then Arr(j) = Arr(j) + 1
Next j
Next i
End Function
你自己填上存放.TXT文件路径 和名称 就行了 试试看是不是符合你的要求
追问
你那个好像不符合题目啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询