POJ 1961
#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; } }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com