如何把出现的次数以小到大和以大到小进行排列?
问题如下图示例:有什么好的编程方法来处理?
最开始我想到的是用数组,冒号分割,那么数字分别在数组 2 4 6 8 ....的位置,但并不好排序。
[此贴子已经被作者于2022-3-4 11:00编辑过]

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
For i = 0 To lenArr - 1 For j = i To lenArr If (CInt(strArr2(i, 1)) > CInt(strArr2(j, 1))) Then t1 = strArr2(i, 0) t2 = strArr2(i, 1) strArr2(i, 0) = strArr2(j, 0) strArr2(i, 1) = strArr2(j, 1) strArr2(j, 0) = t1 strArr2(j, 1) = t2 End If Next Next StrLine = "" For i = 0 To lenArr '组合字符串 StrLine = StrLine & strArr2(i, 0) & ":" & strArr2(i, 1) & vbCrLf Next Text2.Text = StrLine End Sub
Private Sub Form_Load() Me.Hide Dim strArr() As String Dim strArr2() As String Dim StrLine As String Dim buffer As String Open "C:\Users\Admin\Desktop\1.txt" For Input As #1 Do While Not EOF(1) Line Input #1, buffer StrLine = StrLine + buffer + vbCrLf Loop StrLine = Left(StrLine, Len(StrLine) - 1) '读取文件的全部内容,并去除最后一个回车符 Close #1 strArr = Split(StrLine, vbCrLf) '分割成一维数组 lenArr = UBound(strArr) '一维数组的数量 ReDim strArr2(lenArr, 1) '定义一个二维数组 For i = 0 To lenArr '分割成二维数组 t = Split(strArr(i), ":") strArr2(i, 0) = t(0) '记录数据的文字部分 strArr2(i, 1) = t(1) '记录数据的数字部分 Next For i = 0 To lenArr - 1 For j = i To lenArr If (CLng(strArr2(i, 1)) > CLng(strArr2(j, 1))) Then t1 = strArr2(i, 0) t2 = strArr2(i, 1) strArr2(i, 0) = strArr2(j, 0) strArr2(i, 1) = strArr2(j, 1) strArr2(j, 0) = t1 strArr2(j, 1) = t2 End If Next Next StrLine = "" For i = 0 To lenArr '组合字符串 StrLine = StrLine & strArr2(i, 0) & ":" & strArr2(i, 1) & vbCrLf Next StrLine = Left(StrLine, Len(StrLine) - 1) '去除最后面一个回车符 Open "C:\Users\Admin\Desktop\2.txt" For Output As #1 Print #1, StrLine Close #1 End Sub