poj 1961 (求字符串中的重复子串)
2015-05-12 16:58
162 查看
Sample Input
3
aaa
12
aabaabaabaab
0
Sample Output
Test case #1
2 2
3 3
Test case #2
2 2 //aa有2个a
6 2 //aabaab有2个aab
9 3
12 4
0 1 2 3 4 5 6 7 8 9 10 11
a a b a a b a a b a a b 的next数组为
-1 0 1 0 1 2 3 4 5 6 7 8 9
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; const int MAXN=1000010; char T[MAXN]; int next[MAXN]; int n; void getNext() { int j,k; j=0; k=-1; next[0]=-1; while(j < n) { if(k==-1||T[j]==T[k]) { j++; k++; if(j%(j-k)==0&&j/(j-k)>1) printf("%d %d\n",j,j/(j-k)); next[j]=k; } else k=next[k]; } } int main() { int iCase=0; while(scanf("%d",&n),n) { iCase++; scanf("%s",&T); printf("Test case #%d\n",iCase); getNext(); printf("\n"); } return 0; }View Code
相关文章推荐
- poj 1743 字符串 后缀数组 不可重叠最长重复子串
- POJ-1743 Musical Theme 字符串问题 不重叠最长重复子串
- poj 2406 求字符串中重复子串的个数
- 字符串 后缀数组(可重叠的k 次最长重复子串)poj 3261
- poj 1961 Period (最小重复子串 kmp)
- POJ 1961(KMP前缀最长重复子串)
- POJ 1961 Period(KMP求一个串的重复子串)
- 1961 2406 poj 求字符串的最小循环子串
- POJ-3693-Maximum repetition substring(后缀数组-重复次数最多的连续重复子串)
- POJ 1743 Musical Theme (后缀数组,求最长不重叠重复子串)
- POJ 2774 找出2字符串 最长公共连续子串
- POJ 2406(连续重复子串)
- 在字符串中查找最长重复子串的探讨
- POJ 3294 二分找超过一半字符串中存在的子串
- 给定一个字符串,找到最长的子串的长度没有重复字符
- POJ 3450 Corporate Identity(kmp求多个字符串的最长公共子串)
- 字符串中非重复子串
- 字符串hash + 二分答案 - 求最长公共子串 --- poj 2774
- 求一个字符串当中的最长重复子串
- hdoj String 5672 (字符串模拟)求至少有k个不重复的字符的子串个数