#include <bits/stdc++.h> 
using namespace std;

int BF(string s, string t){
int i = 0, j =0;
while(i < s.length() && j < t.length())
if(s[i] == t[j]){
i++;
j++;
}else{
i = i -j + 1; // 如果不相等,那么要回退到开始位置的下一个位置
j = 0;
}
if(j == t.length())
return i - j; // 如果找到该字符串,那么返回比较的起始位置
else
return -1;
}

int main(){
string s = "aababcde", t = "abcd";

cout << "找到了,在父串中的起始位置为:" << BF(s, t);
return 0;
}