poj2752 kmp 进一步运用
2013-01-28 19:22
253 查看
/* 题意:给定字符串,判断哪些下标开始即是它的前缀又是它的后缀 同时,由kMP中next[]的性质可得,模式串的前半部分的字符和后半部分的字符 相同。 */ #include<stdio.h> #include<string.h> #define max 400010 int next[max]; char str[max]; void get_next(char tem[]) { int j=0,k=-1; int len=strlen(tem); next[0]=-1; while(j<len) { if(k==-1||tem[j]==tem[k]) next[++j]=++k; else k=next[k]; } } void output(int n) { if(next >=0) output(next ); if(n>0) printf("%d ",n); } int main() { while(scanf("%s",str)!=EOF) { int t=strlen(str); get_next(str); output(next[t]); printf("%d\n",t); } return 0; }
相关文章推荐
- POJ2752_Seek the Name, Seek the Fame_KMP_对next数组的运用
- poj 2752 KMP(next数组的运用)
- POJ 2752 Seek the Name, Seek the Fame (KMP的next函数运用)
- POJ 2752-Seek the Name, Seek the Fame(KMP的next数组运用)
- poj 2752 seek the name,seek the fame【KMP】
- POJ 2752 Seek the Name, Seek the Fame KMP
- 【KMP】 poj2752 Seek the Name, Seek the Fame
- POJ_2752_KMP-next数组的应用
- poj 2752 Seek the Name, Seek the Fame ---KMP,字符串处理
- poj2752_Seek the Name,Seek the Fame_KMP(next数组定义的应用)
- POJ 2752 - Seek the Name, Seek the Fame(KMP)
- poj2752(kmp的自身失配函数的利用)
- poj 2752 (找既是前缀又是后缀的串的长度)kmp/拓展kmp
- POJ2752 Seek the Name, Seek the Fame(KMP)
- POJ 2752 Seek the Name,Seek the Fame(KMP应用)
- poj 2752 kmp(next数组模板)
- 【POJ 2752 KMP之next】
- poj 2752 Seek the Name, Seek the Fame(KMP应用)
- KMP POJ 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)