标签:
#include<iostream> #include<stdio.h> #define MAXN 1000001 using namespace std; char c[MAXN]; int next[MAXN]; void give_next(int len) { int i; int j; i=0,j=-1; next[0]=-1; while(i < len) { if(j == -1 || c[i] == c[j]) { i ++; j ++; next[i] = j; } else j = next[j]; } } int main() { //freopen("acm.acm","r",stdin); int size; int tem; int tem1; int time = 0; while(scanf("%d",&size) != EOF,size) { cout<<"Test case #"<<++ time<<endl; scanf("%s",c); int i; give_next(size); for(i = 2; i <= size; ++ i) { if(next[i-1] != -1) { tem = i - (next[i]); if(i % tem == 0) { tem1 = i/tem; if(tem1 > 1) cout<<i<<" "<<tem1<<endl; } } } cout<<endl; } }
标签:
原文地址:http://www.cnblogs.com/gavinsp/p/4566587.html