#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
#define error 0
#define ok 1
int bf(string s, string t, int pos)
{
int i = pos;
int j = 0;
int lens = s.length();
int lent = t.length();
while (i <= lens && j < lent)
{
if (s[i] == t[j])
{
i++;
j++;
}
else
{
i= i - j + 1;
j = 0;
}
}
if (j >= lent)
{
return i - j;
}
else
{
return error;
}
return 0;
}
int main()
{
string s = "bbaaabbaba";
string k = "abb";
cout << "主串与子串在第";
cout << bf(s, k, 0);
cout << "个字符处首次匹配" << endl;
return 0;
}
12-25
2530
08-17
1482
09-22
537