BF:Btute Force
模式匹配:字串的定位运算称为串的模式匹配或串匹配
/*
模式匹配BF算法,
使用string和char是不同的
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s="abcdef";
string t="bcd";
int i=0;
int j=0;
while(i<s.size()&&j<t.size())
{
if(s[i]==t[j])
{
i++;
j++;
}
else
{
i=i-j+2;
i=1;
}
}
if(j==t.size())
cout<< i-t.size()+1<<endl;
else
cout<<"no"<<endl;
return 0;
}