#include <Array.au3>
Local $array
Local $read
Local $text
Local $write
Local $handle
Local $i
Local $j
$handle = FileOpen(@ScriptDir & "\w.txt", 0)
$read = FileRead($handle)
FileClose($handle)
$text = StringStripCR($read)
$array = StringSplit($text, @TAB & @LF)
;_ArrayDisplay($array, "处理前")
If BitAND($array[0], 0x00000001) Then
_ArrayDelete($array, $array[0])
$array[0] -= 1
EndIf
For $i = 1 To $array[0]-3 Step 2
For $j = $array[0]-1 To $i+2 Step -2
;ConsoleWrite("i="&$i&" , j="&$j&" , array="&$array[$i]&" , array[j]="&$array[$j] & @CRLF)
If Not StringCompare($array[$i], $array[$j]) Then
$array[$i+1] = Number($array[$i+1])+Number($array[$j+1])
_ArrayDelete($array, $j)
_ArrayDelete($array, $j)
$array[0] -= 2
EndIf
Next
Next
;ArrayDisplay($array, "处理后")
$write = ""
For $i = 1 To $array[0]-1 Step 2
$write &= $array[$i] & @TAB & $array[$i+1] & @CRLF
Next
$handle = FileOpen(@ScriptDir & "\w.txt", 10)
FileWrite($handle, $write)
FileClose($handle)
|