#include#include #include 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; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)