水木子
发表于 2010-8-1 15:53:17
向大虾们学习了,我就纯支持下。
P版的这个《傻子排序》貌似在哪里见过。嘿嘿!!!
pusofalse
发表于 2010-8-1 15:58:02
回复 31# 水木子
QQ空间吗? - -||| 祝水木子兄早日康复。
水木子
发表于 2010-8-1 16:06:46
回复 32# pusofalse
嘿嘿!就是、就是。
康复得差不多了吧!痒痒的,好想抠抠。{:face (368):}
gapkiller
发表于 2010-8-2 00:45:44
正则试试~
如果是这样,估计会把傻子累死~~ O(∩_∩)O
afan 发表于 2010-8-1 14:25 http://www.autoitx.com/images/common/back.gif
帅得一塌糊涂~~
3mile
发表于 2010-8-2 14:30:44
本帖最后由 3mile 于 2010-8-2 14:33 编辑
学写个另类的方案,26个字母的“傻子问题”。
本人笨,理解题经常理解到一边去。
感谢P大出题,希望P大能多出点类似的效率算法类的题。以便学习更多的思维方法。#include <array.au3>
Local $fin
$time = TimerInit()
$str = "POQSTRZIABCDEFGHKJMLNYXWVU"
$st = StringSplit($str, "")
$number = StringLen($str)
$z = $number
While 1
If Asc($st[$z])-64<>$z Then
$soure=$st[$z]
_ArrayDelete($st,$z)
_ArrayInsert($st,Asc($soure)-64,$soure)
For $i=1 To $number
$fin&=$st[$i]
Next
$fin&=","
Else
$z-=1
If $z=0 Then ExitLoop
EndIf
WEnd
_ArrayDisplay($st,TimerDiff($time))
MsgBox(0,TimerDiff($time),$fin)
psp7456
发表于 2010-8-3 02:14:24
本帖最后由 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;在未完成排序前一直循环
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)
9,1,2,3,4,5,6,7,8
9,1,2,3,4,5,6,8,7
9,1,2,3,4,5,7,6,8
9,1,2,3,4,5,7,8,6
9,1,2,3,4,6,5,7,8
9,1,2,3,4,6,5,8,7
9,1,2,3,4,6,7,5,8
9,1,2,3,4,6,7,8,5
9,1,2,3,5,4,6,7,8
9,1,2,3,5,4,6,8,7
9,1,2,3,5,4,7,6,8
9,1,2,3,5,4,7,8,6
9,1,2,3,5,6,4,7,8
9,1,2,3,5,6,4,8,7
9,1,2,3,5,6,7,4,8
9,1,2,3,5,6,7,8,4
9,1,2,4,3,5,6,7,8
9,1,2,4,3,5,6,8,7
9,1,2,4,3,5,7,6,8
9,1,2,4,3,5,7,8,6
9,1,2,4,3,6,5,7,8
9,1,2,4,3,6,5,8,7
9,1,2,4,3,6,7,5,8
9,1,2,4,3,6,7,8,5
9,1,2,4,5,3,6,7,8
9,1,2,4,5,3,6,8,7
9,1,2,4,5,3,7,6,8
9,1,2,4,5,3,7,8,6
9,1,2,4,5,6,3,7,8
9,1,2,4,5,6,3,8,7
9,1,2,4,5,6,7,3,8
9,1,2,4,5,6,7,8,3
9,1,3,2,4,5,6,7,8
9,1,3,2,4,5,6,8,7
9,1,3,2,4,5,7,6,8
9,1,3,2,4,5,7,8,6
9,1,3,2,4,6,5,7,8
9,1,3,2,4,6,5,8,7
9,1,3,2,4,6,7,5,8
9,1,3,2,4,6,7,8,5
9,1,3,2,5,4,6,7,8
9,1,3,2,5,4,6,8,7
9,1,3,2,5,4,7,6,8
9,1,3,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1,2,9,4,3,6,7,5,8
1,2,9,4,3,6,7,8,5
1,2,9,4,5,3,6,7,8
1,2,9,4,5,3,6,8,7
1,2,9,4,5,3,7,6,8
1,2,9,4,5,3,7,8,6
1,2,9,4,5,6,3,7,8
1,2,9,4,5,6,3,8,7
1,2,9,4,5,6,7,3,8
1,2,9,4,5,6,7,8,3
1,2,3,9,4,5,6,7,8
1,2,3,9,4,5,6,8,7
1,2,3,9,4,5,7,6,8
1,2,3,9,4,5,7,8,6
1,2,3,9,4,6,5,7,8
1,2,3,9,4,6,5,8,7
1,2,3,9,4,6,7,5,8
1,2,3,9,4,6,7,8,5
1,2,3,9,5,4,6,7,8
1,2,3,9,5,4,6,8,7
1,2,3,9,5,4,7,6,8
1,2,3,9,5,4,7,8,6
1,2,3,9,5,6,4,7,8
1,2,3,9,5,6,4,8,7
1,2,3,9,5,6,7,4,8
1,2,3,9,5,6,7,8,4
1,2,3,4,9,5,6,7,8
1,2,3,4,9,5,6,8,7
1,2,3,4,9,5,7,6,8
1,2,3,4,9,5,7,8,6
1,2,3,4,9,6,5,7,8
1,2,3,4,9,6,5,8,7
1,2,3,4,9,6,7,5,8
1,2,3,4,9,6,7,8,5
1,2,3,4,5,9,6,7,8
1,2,3,4,5,9,6,8,7
1,2,3,4,5,9,7,6,8
1,2,3,4,5,9,7,8,6
1,2,3,4,5,6,9,7,8
1,2,3,4,5,6,9,8,7
1,2,3,4,5,6,7,9,8
1,2,3,4,5,6,7,8,9
用时28.379117278439毫秒!
zc640618
发表于 2010-8-3 17:12:35
9,1,2,3,4,5,6,7,8
9,1,2,3,4,5,6,8,7
9,1,2,3,4,5,7,6,8
9,1,2,3,4,5,7,8,6
9,1,2,3,4 ...
psp7456 发表于 2010-8-3 02:14 http://www.autoitx.com/images/common/back.gif
这样写貌似高效多了,膜拜...
G,man。
发表于 2010-8-7 09:49:07
都是高手啊,