链接http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1163
#include<iostream> #include<stdio.h> #include<cstring> #include<algorithm> using namespace std; char str[1200],cha[1200],pat[1200],next[1200]; int sta; void get_next( char *word ) { int len = strlen( word ); int k = -1,j = 0; next[0] = -1; while( j < len ) if( k == -1 || str[k] == str[j] ) next[++j] = ++k; else k = next[k]; } int work( char *word ) { int len = strlen( str ); int let = strlen( word ); int i,k = 0; for( i = sta; i < len; i++ ) { while( str[i] != word[k] && next[k] != -1 ) k = next[k]; if( str[i] == word[k] ) k++; if( k == let )return i+1; } return -1; } int main( ) { while( scanf("%s",&str) != EOF ) { scanf("%s",&cha); int len = strlen( cha ); cha[len++] = '*'; int k = 0; bool fell = false; sta = 0; for( int i = 0; i < len; i++ ) { if( cha[i] == '*' ) { if( k == 0 )continue; pat[k] = '\0'; k = 0; get_next( pat );sta = work( pat ); if( sta < 0 ){ fell = true;break; } } else pat[k++] = cha[i]; } if( !fell )printf("yes\n"); else printf("no\n"); } return 0; } /* jfkadjfkdfjafjakjfaksfj ka*jf*ka */