#include<array.au3>
Global $frist[430], $second[430], $third[430], $i = 0, $outarray[431][3], $sum_average, $fir_cha, $sec_cha, $thi_cha, $sum1, $sum2, $sum3
Dim $i_t
;读入数据
For $t = 0 To 429
$shuju_line = StringRegExp(FileReadLine(@ScriptDir & "\数据.txt", $t + 1), '[.\d]+', 3)
$frist[$t] = Number($shuju_line[0])
$second[$t] = Number($shuju_line[1])
$third[$t] = Number($shuju_line[2])
Next
_Mysum()
$sum_average = ($sum1 + $sum2 + $sum3) / 3
While 1
_Mycha()
If $fir_cha = 0 Then
_Mytiaozheng($second, $third, $sec_cha)
ElseIf $sec_cha = 0 Then
_Mytiaozheng($frist, $third, $fir_cha)
ElseIf $thi_cha = 0 Then
_Mytiaozheng($frist, $second, $fir_cha)
ElseIf ($fir_cha > 0 And $second > 0) Or ($fir_cha < 0 And $sec_cha < 0) Then
If Abs($fir_cha) > Abs($sec_cha) Then
_Mytiaozheng($frist, $third, $fir_cha)
Else
_Mytiaozheng($second, $third, $sec_cha)
EndIf
ElseIf ($fir_cha > 0 And $thi_cha > 0) Or ($fir_cha < 0 And $thi_cha < 0) Then
If Abs($fir_cha) > Abs($thi_cha) Then
_Mytiaozheng($frist, $second, $fir_cha)
Else
_Mytiaozheng($third, $second, $thi_cha)
EndIf
ElseIf Abs($sec_cha) > Abs($thi_cha) Then
_Mytiaozheng($second, $frist, $sec_cha)
Else
_Mytiaozheng($third, $frist, $thi_cha)
EndIf
_Mysum()
If $i_t = $i Then ExitLoop
$i_t = $i
WEnd
MsgBox(0, "", "共计调整" & $i & "次!")
_Myout()
_ArrayDisplay($outarray)
;3组数组和及平均值
Func _Mysum()
$sum1 = 0
$sum2 = 0
$sum3 = 0
Local $t
For $t = 0 To 429
$sum1 += $frist[$t]
$sum2 += $second[$t]
$sum3 += $third[$t]
Next
EndFunc ;==>_Mysum
;按差值查看数组是否需要调整
Func _Mytiaozheng(ByRef $temp1, ByRef $temp2, $temp_diff)
Local $m, $n, $temp_change, $temp_min[3] = [Abs($temp_diff), 0, 0], $temp_t
For $m = 0 To 429
For $n = 0 To 429
$temp_change = Abs(($temp_diff) - $temp1[$m] + $temp2[$n])
If $temp_change < $temp_min[0] Then
$temp_min[0] = $temp_change
$temp_min[1] = $m
$temp_min[2] = $n
EndIf
Next
Next
;数据交换
If $temp_min[0] < Abs($temp_diff) Then
$temp_t = $temp1[$temp_min[1]]
$temp1[$temp_min[1]] = $temp2[$temp_min[2]]
$temp2[$temp_min[2]] = $temp_t
$i += 1
EndIf
EndFunc ;==>_Mytiaozheng
;数组输出
Func _Myout()
Local $m
$outarray[0][0] = $sum1
$outarray[0][1] = $sum2
$outarray[0][2] = $sum3
For $m = 1 To 430
$outarray[$m][0] = $frist[$m - 1]
$outarray[$m][1] = $second[$m - 1]
$outarray[$m][2] = $third[$m - 1]
Next
EndFunc ;==>_Myout
;判读差值
Func _Mycha()
$fir_cha = $sum1 - $sum_average
$sec_cha = $sum2 - $sum_average
$thi_cha = $sum3 - $sum_average
EndFunc ;==>_Mycha
结果如下图: