- 1、本文档共16页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
字符串匹配算法(String matching algorithm)
字符串匹配算法(String matching algorithm)
The brute force method, Horspool, Boyer-Moore, Knuth-Morris-Pratt algorithm is used for the performance of different languages, the scale of data on them. The scale of the data should be above 100000.
Int BruteForceStringMatch (string STR, string pattern)
{
For (int i = 0; I = (str.size) - pattern.size (i++);)
{
Int j = 0;
((while) (J pattern.size) (pattern[j] = = str[i+j]))
{
J++;
}
If (J) = (pattern.size)
Return i;
}
Return (-1);
}
Void ShiftTable (string pattern, int table[], Int l)
{
For (int i = 0; I 127; i++)
Table[i] = l;
For (int j = 0; J L-1; j++)
Table[pattern[j]] = l-1-j;
}
Void HorspoolMatch (string STR, int table[], string pSize)
Int (main)
{
String a = abcdefg;
String mode = z;
CoutBruteForceStringMatch (a, mode) endl;
Return 0;
}
#includeiostream
Using namespace std;
Const int HASH_SIZE=256;
Int table[HASH_SIZE]; / / the corresponding character table of 255 characters to build a hash table, said does not match the character to the right moving distance
Void ShiftTable (char pattern[]) {
* to establish a alphabet characters index Table array *
Int m=strlen (pattern);
For (int i=0; iHASH_SIZE; i++)
Table[i]=m;
For (int j=0; jm-1; j++)
Table[pattern[j]]=m-1-j;
}
Int HorspoolMatching (char pattern[], char text[]) {// average efficiency of O (n)
*
Pre: pattern, text text
Post: the first matching string the leftmost character string matching without subscript, return -1 find
* /
ShiftTable (pattern);
Int m=strlen (pattern);
Int n=strlen (text);
Int i=m-1;
While (I n-1) {
Int k=0; / / the number of characters,
While (k=m-1 pattern[m-1-k] = = text[i-k])
K++;
If (k==m)
Return i-m+1;
Else
I=i+table[text[i]]; / / to the last character to determine the moving distance, the biggest difference with the B.M algorithm, a simplified form
}
Return -1;
}
Int (main) {
Char p[20], t[1000];
While (cint T! = {.)
Int times=5;
而(次){
CIN P;
cout horspoolmatching(P,T) endl;
}
}
返回1;
}
#包含iostream
#算法包括
#包括字符串
#包括向量
#则ssize_t
off_
您可能关注的文档
- 重庆周边旅游(Chongqing surrounding Tourism).doc
- 重庆经信委缘何强势(Chongqing commission by letter why strong).doc
- 重庆足下软件学院优势(Chongqing foot software institute advantage).doc
- 重庆旅游景点(Chongqing tourist attractions).doc
- 重庆附近好耍的地方推荐(Near Chongqing where Haoshua).doc
- 重点中药对比记忆02(The Chinese medicine focus on comparative memory 02).doc
- 重现被误删的windows桌面图标(Reproduce the deleted Windows desktop icons).doc
- 野外烧烤(Barbecue).doc
- 金属学10张(10 piece of metal).doc
- 金山人生规划(Jinshan life planning).doc
- 字谜答题(Answer the puzzle).doc
- 存储过程语句(Stored procedure statement).doc
- 孙鑫c++课程目录(Xin Sun c++ course catalog).doc
- 孟良崮战役细节整编七十四师两天打完所带弹药(Menglianggu details two days after the reorganization of the seventy-four division with ammunition).doc
- 孤独型人格(Lonely personality).doc
- 学习教师礼仪心得(Study on Teachers' Etiquette Tips).doc
- 如果你看后觉得没用我去撞墙(If you look after me to feel useless against the wall).doc
- 学习笔记(rtra,rtrd,mpc852t,vxworks)(学习笔记(RTRA,RTRD,MPC852T,VxWorks)).doc
- 学会了以后你的嘴巴会很流利(After your mouth will learn very fluently).doc
- 学前班数学教案(Preschool mathematics teaching).doc
文档评论(0)