#include <string>
#include <iostream>
#include <vector>
using namespace std;
int Imdex_BF(string S,string T,int pos)
{
int i=pos;int j=0;
while (i<=S.length() && j<=T.length())
{
if(S[i]==T[j]){++i;++j;}
else{i=i-j+2;j=0;}
}
if (j>T.length()) return i-T.length();
else return 0;
}
int main() {
string S="aaaaba";
string T="ba";
cout<<"匹配到主串的最后位置为:"<<Imdex_BF(S,T,0)<<endl;
string S1="baaaaaba";
string T1="ba";
cout<<"匹配到主串的最后位置为:"<<Imdex_BF(S1,T1,0)<<endl;
string S2="baacbaba";
string T2="cb";
cout<<"匹配到主串的最后位置为:"<<Imdex_BF(S2,T2,0)<<endl;
return 0;
}