回复 34# binghc
请帮忙再测试下吧.多谢
但是效率应该下降了些.
#include <array.au3>
#include <file.au3>
Local $aArray,$time=TimerInit()
_FileReadToArray('萌动校园.txt',$aArray)
Global $count=$aArray[0]
_ArrayDelete($aArray,0);删除总行数,避免排序出错
$aa = _unique($aArray)
MsgBox(0,'用时:'&TimerDiff($time),'总行数:'&$count)
_FileWriteFromArray('输出.txt',$aa)
_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];,$k=$count,$p=0
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
If $temp[$i][1]>$temp[$i - 1][1] Then
_ArrayDelete($temp,$i)
$i-=1
Else
_ArrayDelete($temp,$i-1)
$i-=1
EndIf
EndIf
If $i=UBound($temp)-1 Then ExitLoop
Next
_ArraySort($temp, 0, 0, 0, 1)
Local $reules[UBound($temp)],$p
For $i=0 To UBound($temp)-1
If $temp[$i][1]=-1 Then ContinueLoop
$reules[$p]=$temp[$i][0]
$p+=1
Next
Return $reules
EndIf
EndFunc ;==>_unique
Func _Min($nNum1, $nNum2)
If (Not IsNumber($nNum1)) Then Return SetError(1, 0, 0)
If (Not IsNumber($nNum2)) Then Return SetError(2, 0, 0)
If $nNum1 > $nNum2 Then
Return $nNum2
Else
Return $nNum1
EndIf
EndFunc ;==>_Min
Func _Max($nNum1, $nNum2)
; Check to see if the parameters are indeed numbers of some sort.
If Not IsNumber($nNum1) Then Return SetError(1, 0, 0)
If Not IsNumber($nNum2) Then Return SetError(2, 0, 0)
If $nNum1 > $nNum2 Then
Return $nNum1
Else
Return $nNum2
EndIf
EndFunc ;==>_Max
|