首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

求一时间复杂度较小的容错的子串算法解决办法

2012-01-08 
求一时间复杂度较小的容错的子串算法问题描述:有一字符串数组A()(只有小写字母和数字)如A(1) asdfghjklj

求一时间复杂度较小的容错的子串算法
问题描述:
有一字符串数组A()(只有小写字母和数字)

A(1)= "asdfghjkljwpef "
A(2)= "asdoghjklaoiefna "
A(3)= "asdoehjklajsldkfj "
用一个字符串S= "sdfgh "匹配(容差一个字符)
则A(1)与A(2)被选中(无需返回子串位置)
可以对字符数组做预处理(时间不算在内)

貌似就是这么多了,我现在想要一个此问题的算法,望各位专家不吝赐教,吾不胜受恩感激!


[解决办法]
Private Sub Command1_Click()
Dim A(3) As String
Dim i As Integer

A(1) = "asdfghjkljwpef "
A(2) = "asdoghjklaoiefna "
A(3) = "asdoehjklajsldkfj "

For i = 1 To 3
If A(i) Like "*sd?gh* " Then Debug.Print "A( " & i & ")被选中 "
Next

End Sub
[解决办法]
Function LikeEx(ByVal sSub As String, ByVal sData As String) As Boolean
Dim iLoop As Integer
LikeEx = False
For iLoop = 1 To Len(sSub)
If sData Like "* " & Left(sSub, iLoop - 1) & "? " & Mid(sSub, iLoop + 1) & "* " Then
LikeEx = True
Exit For
End If
Next iLoop
End Function

Private Sub Form_Load()
Dim A(2) As String
Dim iLoop As Integer

A(0) = "asdfghjkljwpef "
A(1) = "asdoghjklaoiefna "
A(2) = "asdoehjklajsldkfj "

For iLoop = 0 To 2
If LikeEx( "sdfgh ", A(iLoop)) Then Debug.Print "A( " & iLoop + 1 & ")被选中 "
Next
End
End Sub

[解决办法]
请问你,n是什么意思呢?
不要随便写个式子糊弄我...

无语...
楼主你先弄明白时间复杂度表达式的含义, 好不好?
n是问题规模,在这里,可以认为就是数组A的元素个数

热点排行