Period
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1959 Accepted Submission(s): 961
3 aaa 12 aabaabaabaab 0
Test case #1 2 2 3 3 Test case #2 2 2 6 2 9 3 12 4
#include <iostream>
#include <cstring>
using namespace std;
int next[1111111];
char s[1111111];
void getnext(int l) //求next数组
{
int i=0,j=-1;next[i]=j;
while(i<l)
{
if(j==-1||s[i]==s[j])
{
next[++i]=++j;
if(i%(i-next[i])==0&&i/(i-next[i])>1) //对每次求出来的next进行判别,符合输出就输出
cout<<i<<" "<<i/(i-next[i])<<endl;
}
else j=next[j];
}
}
int main (void)
{
int i,k=1,l;
while(cin>>l&&l)
{
cin>>s;
cout<<"Test case #"<<k++<<endl;
getnext(l);
cout<<endl;
}
return 0;
}