//10170330 容易
#include <cstdio>
#include <iostream>
#include <cstring>
#define ERROR 0
#define MAXSIZE 100
using namespace std;
//串的暴力匹配算法(brute force)
//该函数的作用是返回子z串T在S中第position个字符之后的位置
//时间复杂度为o(mn),其中m和n分别是文本串和模式串的长度
//当m和n都是10^ 5级别时,用暴力解法完全无法接受
//代码如下:
int Index_BF(char *S,char *T,int position)
{
int m=position;
int n=0;
while(S[m+n]!='\0'&&T[n]!='\0')//循环条件
if(S[m+n]==T[n])//相对应的字符匹配上
n++;//T后移一位
else
{
m++;
n=0;
}//S后移一位,同时让T指向开头
暴力匹配算法,首尾匹配算法,KMP算法
最新推荐文章于 2023-09-05 22:41:05 发布