bmhs算法
#include<string.h>
main()
{
char *text="substering searching algorithm search";
char *patt="search",* match_text;
int shift[256];
int patt_size=strlen(patt);
int i;
int text_size,limit,match_size;
for(i=0;i<256;i++)
shift[i]=patt_size+1;
for(i=0;i<patt_size;i++)
*(shift+(*(patt+i)))=patt_size-i;
text_size=strlen(text);
limit=text_size-i+1;
for(i=0;i<limit;i+=shift[text[i+patt_size] ] )
{
if(text[i]==*patt)
{
match_text=text+i+1;
match_size=1;
do{
if(match_size==patt_size)
printf("i = %d\n", i);
}while( (*match_text++)==patt[match_size++] );
}
}
}