#include<iostream>
#include<string>
using namespace std;
int IsIn(const string match,char ch){
int i=0,size=match.size();
for(;i<size;i++)
if(ch == match[i])
return size - i ;//找到
return -1;//未找到
}
int The(const string pattern,const string match){
int i=0,j=0,matchSize=match.size(),patternSize=pattern.size();
while(i<patternSize&&j<matchSize){
if(pattern[i] == match[j]){
i++;
j++;
}else{
if(i - j + matchSize >= (patternSize>>1)){
j=0;
i++;
continue;
}
int flag = IsIn(match,pattern[i - j + matchSize ]);
j=0;
if(flag == -1)
i = i + matchSize + 1 ;
else
i += flag;
}
}
return i - j;
}
int main(){
const string a="substring searching algorithm", b = "algorithm";
cout<<The(a,b);
return 0;
}
我在写啥卧槽