| ||||||||||
| 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 | |||||||||
定义变量时略作修改即可ACIn Reply To:o(n)还TLE?! Posted by:waterine at 2005-04-27 00:26:52 > #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