| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 14726 | Accepted: 7009 |
Description
Input
Output
Sample Input
3 aaa 12 aabaabaabaab 0
Sample Output
Test case #1 2 2 3 3 Test case #2 2 2 6 2 9 3 12 4
Source
AC code:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define maxn 1000005
using namespace std;
int next[maxn];
int main(){
char s[maxn];
int loop=1;
int k,len,i,j;
while(cin>>len&&len){
scanf("%s",s);
printf("Test case #%d\n",loop++);
j=0,k=-1;
next[0]=-1;
while(j<len){
if(k==-1||s[j]==s[k]){
j++;k++;
next[j]=k;
}
else k=next[k];
}
for(int i=1;i<=len;++i){
///printf("next[%d]: %d \n",i,next[i]);
if(i%(i-next[i])==0&&i/(i-next[i])>1)
printf("%d %d\n",i,i/(i-next[i]));
}
putchar('\n');
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/zp___waj/article/details/47681241