标签:des style blog color io os ar java for
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3196 Accepted Submission(s): 1603
1 #include <stdio.h> 2 #include <string.h> 3 #define N 1000000 4 5 int n; 6 char str[N]; 7 int p[N]; 8 9 void run(void) 10 { 11 memset(p,-1,sizeof(p)); 12 for(int i=1;i<n;i++) 13 { 14 int k=p[i-1]; 15 while(1) 16 { 17 if(str[k+1]==str[i]) 18 { 19 p[i]=k+1; 20 if((i+1)%(i-p[i])==0) 21 printf("%d %d\n",i+1,(i+1)/(i-p[i])); 22 break; 23 } 24 if(k==-1)break; 25 k=p[k]; 26 } 27 } 28 } 29 30 int main() 31 { 32 int id=0; 33 while(scanf("%d",&n)==1&&n) 34 { 35 getchar(); 36 gets(str); 37 printf("Test case #%d\n",++id); 38 run(); 39 puts(""); 40 } 41 }
标签:des style blog color io os ar java for
原文地址:http://www.cnblogs.com/lovychen/p/4032757.html