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 |
AC#include<cstdio> #include<cstring> char s[1000005],k[1000005]; int len,len1; int f[1000005]; int num; void qs () { f[0]=-1; int i=1,j=-1; for (;i<len;i++) { while (j!=-1&&s[i]!=s[j+1]) j=f[j]; if (s[i]==s[j+1]) j++; f[i]=j; } } int main() { while (true) { scanf("%s",s); if (strcmp(s,".")==0) break; len=strlen(s); qs(); //for (int u=0;u<len;u++) printf("%d ",f[u]); int t=len-f[len-1]-1; //printf("%d\n",t); if (t==0) printf("1"); else if (len%t==0) printf("%d",len/t); else printf("1"); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator