poj 2406 求字符串中重复子串的个数
2015-05-12 17:00
295 查看
Sample Input
abcd
aaaa
ababab
.
Sample Output
1 //1个abcd
4 //4个a
3 //3个ab
#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++; next[j]=k; } else k=next[k]; } if(n%(n-k)==0) printf("%d\n",n/(n-k)); else printf("1\n") ; } int main() { while(scanf("%s",&T) != EOF) { if (T[0]=='.') break ; n = strlen(T) ; getNext(); } return 0; }View Code
相关文章推荐
- poj 2406 kmp求连续重复子串的个数
- POJ-1743 Musical Theme 字符串问题 不重叠最长重复子串
- poj 2406 Power Strings(kmp求一个串的重复子串)
- POJ 2406(连续重复子串)
- poj 2406 KMP 重复子串
- POJ - 2406 Power Strings解题报告(KMP,字符串划分成若干连续相同子串)
- (字符串的模式匹配4.7.18)POJ 2406 Power Strings(求一个字符串的最小重复串)
- (字符串的模式匹配4.7.18)POJ 2406 Power Strings(求一个字符串的最小重复串)
- POJ 2406-Power Strings(重复子串-KMP中的next数组)
- poj(2406)求最短重复子串-KMP
- poj 2406 Power Strings(连续重复子串)
- POJ 2406 后缀数组:求连续重复子串
- POJ 2406 Power Strings(KMP求一个串的重复子串)
- poj 1961 (求字符串中的重复子串)
- poj 2406 连续重复子串(后缀数组DC3/kmp)
- poj 2406 求连续重复子串出现的次数 后缀数组
- 1961 2406 poj 求字符串的最小循环子串
- 【POJ 2406】Power Strings 连续重复子串
- POJ-2406 Power Strings(KMP求重复子串出现的最大次数)
- 字符串 后缀数组(可重叠的k 次最长重复子串)poj 3261