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 |
因为太慢了,考虑hash和kmpIn Reply To:为什么tle Posted by:Headacher at 2008-10-17 23:31:40 > #include<iostream> > #include<cstring> > using namespace std; > char s[1000000]; > int main() > { while(scanf("%s",s)) > { int len=strlen(s); > if(s[0]=='.') > break; > int i,j; > for(i=1;;i++) > { bool can=1; > for(j=0;j<i;j++) > { > int k; > for(k=j;;k=k+i) > { if(k+i>=len) > { break; > } > if(s[k]!=s[k+i]) > { can=0;//i不能用,break > break; > } > > } > if(can==0)//i不能用,找i+1 > break; > > } > if(can==1)//i可以用输出len/i > break; > > } > printf("%d\n",len/i); > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator