如何用au3 分别统每组号码里面出现三次以上的号
我这里有100组号码每组号码又分5行每行有5个数字 如何分别统每组号码里面出现三次以上的号码27,39,55,75,76
27,41,69,75,76
34,46,51,75,76
3,20,63,69,73
11,58,69,75,76
(比如这组有75 76 69)
2,3,39,51,73
2,3,5,53,72
26,27,33,39,72
26,27,68,75,76
3,4,5,68,75
(比如这组有3)
2,3,39,69,76
5,8,26,72,76
27,68,69,75,76
4,11,27,33,69
5,26,39,51,72
(比如这组有76 69 )
27,33,57,68,73
2,3,39,69,75
2,3,27,33,45
2,3,68,69,76
26,27,33,72,73
2,27,57,71,75
39,57,71,73,75
14,51,58,72,76
39,57,73,75,76
39,68,69,75,76
2,20,26,65,71
2,27,39,57,68
2,39,51,53,73
8,20,33,51,57
3,41,68,69,76
3,27,69,75,76
2,14,27,57,69
2,33,69,71,75
2,39,72,75,76
39,58,72,73,76
3,48,68,71,75
3,57,68,69,73
2,51,57,68,71
26,27,68,69,76
3,26,57,68,69
3,8,58,72,76
11,33,63,69,75
2,3,48,65,76
5,27,51,75,76
27,68,72,75,76
2,3,33,51,72
57,68,72,75,76
5,27,68,72,76
27,34,46,57,72
26,27,51,57,71
3,51,71,72,73
2,3,68,69,72
2,3,27,39,46
3,26,72,75,76
2,3,51,57,71
2,3,58,69,76
4,26,60,75,76
3,14,39,68,71
26,46,51,63,75
写个比较简单的处理方式,利用INI格式
#Include<array.au3>
Local $ini = @ScriptDir&"\临时存储用.ini"
Local $string = _
'27,39,55,75,76' & @CRLF & _
'27,41,69,75,76' & @CRLF & _
'34,46,51,75,76' & @CRLF & _
'3,20,63,69,73' & @CRLF & _
'11,58,69,75,76'
;将组一数据转成 数组
Local $g1 = StringSplit(StringReplace($string,@crlf,","),",")
IniDelete($ini,"组1") ;预先删除组,临时用---
For $i = 1 To $g1
;---------------------------重点是这里,利用Ini格式不可重复性来处理------
Local $rd = IniRead($ini,"组1",$g1[$i],0)
IniWrite($ini,"组1",$g1[$i],$rd+1)
;---------------------------
Next
Local $rG1 = IniReadSection($ini,"组1") ;读取 [组1] 内键与值
Local $rec = "" ;用于循环接收保存数据
For $i = 1 To$rG1
If $rG1[$i] > 2 Then $rec &=$rG1[$i]&",";对比数组中 值大于2 的,保存
Next
MsgBox(0,"结果",$rec)
**** Hidden Message *****
看看算法 学习一下这种类型的分析统计代码 #include <Array.au3>
; 定义输入数据,每组号码之间用字符串表示,每行使用分号分隔
Local $sData = "27,39,55,75,76;27,41,69,75,76;34,46,51,75,76;3,20,63,69,73;11,58,69,75,76|" & _
"2,3,39,51,73;2,3,5,53,72;26,27,33,39,72;26,27,68,75,76;3,4,5,68,75|" & _
"2,3,39,69,76;5,8,26,72,76;27,68,69,75,76;4,11,27,33,69;5,26,39,51,72"
; 其他组可以继续按此格式添加
; 以竖线分隔每组数据,转换为数组
Local $aGroups = StringSplit($sData, "|", 1)
; 逐组处理数据
For $i = 1 To $aGroups
; 将每组的行数据以分号分隔成数组
Local $aLines = StringSplit($aGroups[$i], ";", 1)
Local $oDict = ObjCreate("Scripting.Dictionary")
; 统计每个数字出现的次数
For $j = 1 To $aLines
Local $aNumbers = StringSplit($aLines[$j], ",", 1)
For $k = 1 To $aNumbers
Local $sNumber = StringStripWS($aNumbers[$k], 3) ; 去除前后空白
If $oDict.Exists($sNumber) Then
$oDict.Item($sNumber) += 1
Else
$oDict.Add($sNumber, 1)
EndIf
Next
Next
; 找到出现三次及以上的数字
Local $sFrequentNumbers = ""
For $Key In $oDict
If $oDict.Item($Key) >= 3 Then
$sFrequentNumbers &= $Key & ", "
EndIf
Next
; 去除最后一个逗号和空格,并输出结果
If StringRight($sFrequentNumbers, 2) = ", " Then
$sFrequentNumbers = StringTrimRight($sFrequentNumbers, 2)
EndIf
ConsoleWrite("第 " & $i & " 组:出现三次及以上的数字有:" & $sFrequentNumbers & @CRLF)
Next
每天学习新知识!
页:
[1]