题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2087
就是给你一个串和一个模式串,问,这个串中有多少个模式串。
就是KMP啦,稍微修改一下就是匹配成功后返回匹配成功后的最后一个字符的位置的后一位,而不是第一位。因为是剪纸啦,不能剪过的再剪一次是吧。。
1 #include2 #include 3 int next[1005]; 4 void get_next(char t[1005]) 5 { 6 int i=0,j=-1,len; 7 next[0]=-1; 8 len=strlen(t); 9 while(i =lent) return i;32 else return 0;33 }34 int main()35 {36 char t[1005],s[1005],ch,f,len;37 int i,sum;38 scanf("%s",s);39 while(s[0]!='#')40 {41 scanf("%s",t);42 i=0;43 len=strlen(s);44 get_next(t);45 sum=0;f;46 while(i