VB如何统计数字数量,出现次数由多到小排列
如有这样的数字:8699444333333777711111111,计算其次数并由大到小从上向下显示出来1有8个3有6个7有4个4有3个9有2个8有1个6有1个...
如有这样的数字:8699444333333777711111111,计算其次数并由大到小从上向下显示出来
1有8个
3有6个
7有4 个
4有3个
9有2个
8有1个
6有1个 展开
1有8个
3有6个
7有4 个
4有3个
9有2个
8有1个
6有1个 展开
1个回答
展开全部
Dim a(0 To 9, 0 To 1) As Integer
Dim i As Integer, str As String, tmp As Integer
str = "8699444333333777711111111"
For i = 1 To Len(str) '统计
If IsNumeric(Mid(str, i, 1)) Then a(Mid(str, i, 1), 1) = a(Mid(str, i, 1), 1) + 1
Next
For i = 0 To 9
a(i, 0) = i
Next i
For i = 0 To 9 '排序
For j = i + 1 To 9
If a(i, 1) < a(j, 1) Then
tmp = a(i, 0): a(i, 0) = a(j, 0): a(j, 0) = tmp
tmp = a(i, 1): a(i, 1) = a(j, 1): a(j, 1) = tmp
End If
Next j
Next i
For i = 0 To 9 '打印
If a(i, 1) <> 0 Then Print a(i, 0) & "有" & a(i, 1) & "个"
Next i
Dim i As Integer, str As String, tmp As Integer
str = "8699444333333777711111111"
For i = 1 To Len(str) '统计
If IsNumeric(Mid(str, i, 1)) Then a(Mid(str, i, 1), 1) = a(Mid(str, i, 1), 1) + 1
Next
For i = 0 To 9
a(i, 0) = i
Next i
For i = 0 To 9 '排序
For j = i + 1 To 9
If a(i, 1) < a(j, 1) Then
tmp = a(i, 0): a(i, 0) = a(j, 0): a(j, 0) = tmp
tmp = a(i, 1): a(i, 1) = a(j, 1): a(j, 1) = tmp
End If
Next j
Next i
For i = 0 To 9 '打印
If a(i, 1) <> 0 Then Print a(i, 0) & "有" & a(i, 1) & "个"
Next i
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询