本帖最后由 supersp 于 2010-4-14 11:53 编辑
楼主1楼的代码,似乎距离算的多了..
我的跟4楼的算的一样..
时间好像很长啊,30ms一个较长的字符串..
下面这个算法只有一个算距离的方法,相似度转换一下就可以#include <Math.au3>
#Include <Array.au3>
$S ='1000101011001110101010011000'
$P ='011100000110011111101000110100010000'
MsgBox (0,"",execSTR($s,$p))
Func execSTR($strA, $strB);返回字符距离
$lenA = StringLen($strA)
$lenB = StringLen($strB)
Dim $c[$lenA+1][$lenB+1]
For $i=0 To $lenA-1 Step 1
$c[$i][$lenB]= $lenA - $i
Next
For $j=0 To $lenB-1 Step 1
$c[$lenA][$j] = $lenB - $j
Next
$c[$lenA][$lenB] = 0
For $i = $lenA-1 To 0 Step -1
For $j = $lenB-1 To 0 Step -1
if(StringMid($strB,$j,1) == StringMid($strA,$i,1)) Then
$c[$i][$j] = $c[$i+1][$j+1]
else
$c[$i][$j] = minValue($c[$i][$j+1], $c[$i+1][$j], $c[$i+1][$j+1]) + 1
EndIf
Next
Next
; _ArrayDisplay($c)
return $c[0][0]
EndFunc
Func minValue($a,$b,$c)
Return _Min(_Min($a,$b),_Min($a,$c))
EndFunc
|