#include <iostream>
#include <string>
using namespace std;
int Length(string str)
{
int cout = 0;
int i = 0;
while(str[i] != '\0')
{
cout++;
i++;
}
return cout;
}
int Index(string S, string T)
{
int i = 0;
int j = 0;
int s = Length(S);
int t = Length(T);
while (i <= s-1 && j <= t-1)
{
if (S[i] == T[j])
{
++i;
++j;
}
else
{
i = i - j + 1;
j = 0;
}
}
if (j > t - 1)
{
return i - (t - 1);
}
else
{
return 0;
}
}
void test01()
{
string S = "hellohahahawangjiabo";
string T = "wangjiabo";
int pos;
pos = Index(S, T);
cout << "子串在主串中匹配的位置为:" << pos << endl;
}
int main()
{
test01();
system("pause");
return 0;
}