回复 27# binghc
写成函数形式,使用REDIM,也许效率会下降.
不知道解决了排序出错的问题了吗?请测试下.
#include <array.au3>
#include <file.au3>
Local $aArray,$time=TimerInit()
_FileReadToArray('test.txt',$aArray)
$count=$aArray[0]
_ArrayDelete($aArray,0);删除总行数,避免排序出错
$aa = _unique($aArray)
MsgBox(0,'用时:'&TimerDiff($time),'总行数:'&$count)
_ArrayDisplay($aa)
Func _unique($aArray)
If Not IsArray($aArray) Then Return SetError(1);非数组
Local $rows = UBound($aArray), $cols = UBound($aArray, 2), $dims = UBound($aArray, 0)
If $dims > 2 Then Return SetError(2);非一维或二维数组
If $dims = 2 Then
Local $temp[$rows][$cols + 1]
For $n = 0 To $cols
If $n < $cols Then
For $i = 0 To $rows - 1
$temp[$i][$n] = $aArray[$i][$n]
Next
Else
For $i = 0 To $rows - 1
$temp[$i][$n] = $i
Next
;_ArrayDisplay($temp)
EndIf
Next
_ArraySort($temp)
For $i = 1 To $rows - 1
If $temp[$i][0] == $temp[$i - 1][0] Then $temp[$i - 1][$cols] = -1
Next
_ArraySort($temp, 0, 0, 0, $cols)
Local $k = 0, $y = 0, $p = 0, $reules[1][$cols]
For $n = 0 To $cols - 1
For $i = 1 To $rows - 1
If $temp[$i][$cols] > -1 Then
$p = UBound($reules)
ReDim $reules[$p + 1][$cols]
$reules[$k][$n] = $temp[$i][$n]
$k += 1
If $reules[$p - 1][0] == '' Then _ArrayDelete($reules, $p - 1)
EndIf
Next
$k = $y
$y += 1
Next
_ArrayDelete($reules, UBound($reules) - 1)
Return $reules
Else
Local $temp[$rows][2]
For $i = 0 To $rows - 1
$temp[$i][0] = $aArray[$i]
$temp[$i][1] = $i
Next
_ArraySort($temp)
For $i = 1 To UBound($temp) - 1
If $temp[$i][0] == $temp[$i - 1][0] Then $temp[$i - 1][1] = -1
Next
_ArraySort($temp, 0, 0, 0, 1)
Local $k=0,$reules[1]
For $i=0 To UBound($temp)-1
If $temp[$i][1]=-1 Then ContinueLoop
ReDim $reules[$k+2]
$reules[$k]=$temp[$i][0]
$k+=1
Next
_ArrayDelete($reules,UBound($reules))
Return $reules
EndIf
EndFunc ;==>_unique
|