标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4437 Accepted Submission(s): 2145
1 #include<stdio.h> 2 const int MAXN=1000010; 3 int N; 4 char m[MAXN]; 5 int next[MAXN]; 6 void getnext(){ 7 int i=0,j=-1; 8 next[i]=j; 9 while(i<N){ 10 if(j==-1||m[i]==m[j]){ 11 i++;j++; 12 next[i]=j; 13 } 14 else j=next[j]; 15 } 16 } 17 void print(int x){ 18 for(int i=1;i<=x;i++){ 19 if(next[i]!=0&&i%(i-next[i])==0)printf("%d %d\n",i,i/(i-next[i])); 20 } 21 } 22 int main(){ 23 int flot=0; 24 while(~scanf("%d",&N),N){ 25 scanf("%s",m); 26 getnext(); 27 //for(int i=0;i<=N;i++)printf("%d ",next[i]);puts(""); 28 //if(flot)puts(""); 29 printf("Test case #%d\n",++flot); 30 print(N); 31 puts(""); 32 } 33 return 0; 34 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4711719.html