#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
#define error 0
#define ok 1
int df(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[i])
{
i++;
j++;
}
else
{
j = i-j+1;
j = 0;
ans++;
}
}
if (j >= lent)
{
return i - j;
}
else
{
return error;
}
return 0;
}
int main ()
{
string s = "bbaaabbaba";
string k = "abb";
cout << "主串与子串在第";
cout << df(s, k, 0);
cout << "个字符处首次匹配" << endl;
return 0;
}
|