//有BUG
#include <iostream>
using namespace std;
int Search(char *str, char nextchar)
{
int length = strlen(str);
while(length-- >0)
{
if(nextchar == str[length - 1])
return length -1;
}
return -1;
}
int Jud(char * str1 , int n1, char *str2 , int n2 )
{
int n2_temp = n2 - n1;
int length = strlen(str1);
int i = 0;
while(length-- > 0)
{
if(str1[i++] != str2[n2_temp++]) break;
}
if(length == -1)
return 1;
return 0;
}
int comp(char * str1, char *str2 )
{
int n_temp = 0;
int n1 = 0;
int n2 = 0;
char nextchar;
while(1)
{ if(str2[n2+1] == '\0')
return 0;
if(Jud(str1,n1,str2,n2) == 1) return 1;
if(n_temp == 0)
{
n_temp = strlen(str1);
n2 = n_temp;
}
nextchar = str2[++n2];
while(str2[n2] != '\0')
{
if((n1 = Search(str1,nextchar)) >= 0) break;
else
{
n2++;
nextchar = str2[n2];
}
if(nextchar == '\0')
return 0;
}
}
}
void main()
{
char str2[] ={"substring searching"};
char str1[] = {"subs"};
cout<<comp(str1,str2 )<<endl;
system("pause");
}