HDU 1686 Oulipo(KMP)
2015-03-30 22:25
405 查看
模板题。。新技能get
#include <stdio.h> #include <string.h> int next[10005]; char str1[1000005],str2[10005]; int cnt; void get_next(int len2)//生成next数组 { int i = 0,j = -1; next[0] = -1; while (i<len2) { if(j == -1 || str2[i] == str2[j]) { i++; j++; if (str2[i]!=str2[j]) next[i] = j; else next[i] = next[j]; } else j = next[j]; } } int kmp(int len1,int len2)//kmp算法 { int i=0,j=0; get_next(len2); while(i<len1) { if(j==-1||str1[i]==str2[j]) { ++i; ++j; } else j=next[j]; if(j == len2) { cnt++; j = next[j]; } } } int main() { int n; int len1,len2; scanf("%d",&n); getchar(); while(n--) { gets(str2); gets(str1); len1 = strlen(str1); len2 = strlen(str2); cnt = 0; kmp(len1,len2); printf("%d\n",cnt); } return 0; }
相关文章推荐
- HDU 1686 Oulipo(KMP)
- HDU-1686 Oulipo(kmp模板题)
- HDU 1686 Oulipo(KMP)
- HDU - 1686 Oulipo KMP匹配运用
- Oulipo (HDU_1686) KMP
- KMP——HDU 1686 Oulipo
- Hdu 1686 Oulipo[kmp]
- HDU 1686 Oulipo kmp入门
- HDU 1686 Oulipo(KMP)
- POj 3461 Oulipo ,HDU 1686 Oulipo(KMP)
- hdu 1686(Oulipo) KMP基础题 / hdu 2087(剪花布条)KMP基本运用
- HDU:1686 Oulipo(KMP包含字符串(不是分割))
- HDU 1686:Oulipo 【KMP】
- Oulipo (poj 3461&&hdu 1686) KMP
- hdu 1686 Oulipo (kmp)
- HDU 1686 Oulipo——kmp
- KMP——HDU 1686 Oulipo
- hdu-1686-Oulipo(KMP)
- hdu 1686 Oulipo kmp
- Oulipo (poj 3461&&hdu 1686) KMP