Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
o(n)还TLE?!#include <stdio.h> #include <string.h> void main() { char str[1000]; int next[1000]; int len; int i,j; while(1) { scanf("%s",str); if(str[0]=='.') return; len=strlen(str); i=0, j=-1; next[0] = -1; while(i<len) { if(j==-1||(j>=0&&str[i]==str[j])) { i++; j++; next[i]=j; } else j=next[j]; } i-=j; if(len%i==0)i=len/i; else i=1; printf("%d\n",i); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator