KMP模板!
1 int BFMatch(char *s,char *p) 2 { 3 int i,j; 4 i=0; 5 while(i<strlen(s)) 6 { 7 j=0; 8 while(s[i]==p[j]&&j<strlen(p)) 9 { 10 i++; 11 j++; 12 } 13 if(j==strlen(p)) 14 return i-strlen(p); 15 i=i-j+1; //指针i回溯 16 } 17 return -1; 18 }
1 int BFMatch(char *s,char *p) 2 { 3 int i,j; 4 i=0; 5 while(i<strlen(s)) 6 { 7 j=0; 8 while(s[i]==p[j]&&j<strlen(p)) 9 { 10 i++; 11 j++; 12 } 13 if(j==strlen(p)) 14 return i-strlen(p); 15 i=i-j+1; //指针i回溯 16 } 17 return -1; 18 }