本帖最后由 psp7456 于 2010-8-3 02:16 编辑 #Include <Array.au3>
func _Main($String);$String:待处理字符串
local $i,$j;循环下标
local $length=stringlen($String);字符长度
local $count=0;记录数字和所在位数均相等的数量
local $temp;临时记录数字值
local $num=0;记录排序次数
Dim $pos[$length+1];定义按位记录待排序数据的数组
$pos=stringsplit($String,"");将待排序数据转换成数组
ConsoleWrite("["&$num&"]"&_ArrayToString($pos,",",1,$length) & @CR);初始顺序
while $count<>$pos[0];在未完成排序前一直循环
for $i=$length to 1 step -1 ;从最右边开始逐位判断
if $pos[$i]=$i then ;如果位数和值相等,则表示排序正确
$count=$count+1
else ;否则要进行换位操作
$temp=$pos[$i]
for $j=$i to $pos[$i] step -1
$pos[$j]=$pos[$j-1]
next
$pos[$temp]=$temp
$num=$num+1
ConsoleWrite("["&$num&"]"&_ArrayToString($pos,",",1,$length) & @CR);输入中间结果
ExitLoop
endif
next
Wend
endfunc
local $begin = TimerInit()
_Main("912345678")
ConsoleWrite("用时"&TimerDiff($begin)&"毫秒!"& @CR)
[0]9,1,2,3,4,5,6,7,8
[1]9,1,2,3,4,5,6,8,7
[2]9,1,2,3,4,5,7,6,8
[3]9,1,2,3,4,5,7,8,6
[4]9,1,2,3,4,6,5,7,8
[5]9,1,2,3,4,6,5,8,7
[6]9,1,2,3,4,6,7,5,8
[7]9,1,2,3,4,6,7,8,5
[8]9,1,2,3,5,4,6,7,8
[9]9,1,2,3,5,4,6,8,7
[10]9,1,2,3,5,4,7,6,8
[11]9,1,2,3,5,4,7,8,6
[12]9,1,2,3,5,6,4,7,8
[13]9,1,2,3,5,6,4,8,7
[14]9,1,2,3,5,6,7,4,8
[15]9,1,2,3,5,6,7,8,4
[16]9,1,2,4,3,5,6,7,8
[17]9,1,2,4,3,5,6,8,7
[18]9,1,2,4,3,5,7,6,8
[19]9,1,2,4,3,5,7,8,6
[20]9,1,2,4,3,6,5,7,8
[21]9,1,2,4,3,6,5,8,7
[22]9,1,2,4,3,6,7,5,8
[23]9,1,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,4,5,3,7,6,8
[219]1,2,9,4,5,3,7,8,6
[220]1,2,9,4,5,6,3,7,8
[221]1,2,9,4,5,6,3,8,7
[222]1,2,9,4,5,6,7,3,8
[223]1,2,9,4,5,6,7,8,3
[224]1,2,3,9,4,5,6,7,8
[225]1,2,3,9,4,5,6,8,7
[226]1,2,3,9,4,5,7,6,8
[227]1,2,3,9,4,5,7,8,6
[228]1,2,3,9,4,6,5,7,8
[229]1,2,3,9,4,6,5,8,7
[230]1,2,3,9,4,6,7,5,8
[231]1,2,3,9,4,6,7,8,5
[232]1,2,3,9,5,4,6,7,8
[233]1,2,3,9,5,4,6,8,7
[234]1,2,3,9,5,4,7,6,8
[235]1,2,3,9,5,4,7,8,6
[236]1,2,3,9,5,6,4,7,8
[237]1,2,3,9,5,6,4,8,7
[238]1,2,3,9,5,6,7,4,8
[239]1,2,3,9,5,6,7,8,4
[240]1,2,3,4,9,5,6,7,8
[241]1,2,3,4,9,5,6,8,7
[242]1,2,3,4,9,5,7,6,8
[243]1,2,3,4,9,5,7,8,6
[244]1,2,3,4,9,6,5,7,8
[245]1,2,3,4,9,6,5,8,7
[246]1,2,3,4,9,6,7,5,8
[247]1,2,3,4,9,6,7,8,5
[248]1,2,3,4,5,9,6,7,8
[249]1,2,3,4,5,9,6,8,7
[250]1,2,3,4,5,9,7,6,8
[251]1,2,3,4,5,9,7,8,6
[252]1,2,3,4,5,6,9,7,8
[253]1,2,3,4,5,6,9,8,7
[254]1,2,3,4,5,6,7,9,8
[255]1,2,3,4,5,6,7,8,9
用时28.379117278439毫秒! |