#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=0;
while (j < T.length()){
if(S[i+j]==T[j]){++j;}
else{break;}
}
if (j == T.length()) return i;
++i;
}
return -1;
}
int main() {
string S="sdfasdfsdfaba";
string T="ba";
cout<<"匹配到主串的位置为:"<<Imdex_BF(S,T,0)<<endl;
string S1="basdfaabfsddfa";
string T1="ba";
cout<<"匹配到主串的位置为:"<<Imdex_BF(S1,T1,0)<<endl;
string S2="bsdfcbasdfba";
string T2="cb";
cout<<"匹配到主串的位置为:"<<Imdex_BF(S2,T2,0)<<endl;
return 0;
}