作业帮 > 综合 > 作业

有一英文文章,vb编程统计出26个字母中,出现频率最高的前5个字母,不区分大小写

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/18 05:14:39
有一英文文章,vb编程统计出26个字母中,出现频率最高的前5个字母,不区分大小写
有一英文文章,vb编程统计出26个字母中,出现频率最高的前5个字母,不区分大小写
Private Sub Command1_Click()
Dim t As String,c As String,s(25) As Long,n(25) As Long,i As Long,j As Long,k As Long
Open "e:\tmp\123.txt" For Binary As #1
t = Input(LOF(1),#1)
Close #1
For i = 0 To 25
n(i) = i
Next
For i = 1 To Len(t)
c = LCase(Mid(t,i,1))
If c >= "a" And c <= "z" Then s(Asc(c) - Asc("a")) = s(Asc(c) - Asc("a")) + 1
Next
For i = 0 To 24
For j = i + 1 To 25
If s(i) < s(j) Then
k = s(i)
s(i) = s(j)
s(j) = k
k = n(i)
n(i) = n(j)
n(j) = k
End If
Next
Next
For i = 0 To 4
Print "No."; i + 1,Chr(n(i) + Asc("a")); " ("; s(i); ")"
Next
End Sub
以上代码假定英文文章是在e:\tmp\123.txt文件中
再问: 咋会 下标越界 指向n(i) = i 有误
再答: n(25) As Long这个声明了吗?声明了的话应该不会有错的。 另外整个窗体代码的通用部分不能有 Option Base 1 我已经测试通过了。