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 |
想知道为什么错了看了就知道了#include <stdio.h> #include <string.h> int next[1000010],len; char str[1000010]; void getnext() { int j,k; j=0; k=-1; memset(next,0,sizeof(next)); next[0]=-1; while(j<len) { if(k==-1||str[j]==str[k]) { j++; k++; next[j]=k; } else k=next[k]; } } int main() { while(scanf("%s",str)!=EOF) { if(strcmp(str,".")==0) break; len=strlen(str); getnext(); if (len%(len-1-next[len-1])) printf("1\n"); else printf("%d\n", len/(len-1-next[len-1])); } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator