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> void getnext(char t[],int next[]) { int i,j; next[1]=0; i=1;j=0; while(i<(int)strlen(t)) { if(j==0||t[i]==t[j]) { i++;j++; next[i]=j; } else { j=next[j]; } } } void main() { char t[1000001];int next[10000];long sum,n; scanf("%s",t); while(strcmp(t,".")!=0) { n=strlen(t); getnext(t,next); if(n==2) { if(t[0]==t[1])printf("2\n"); else printf("1\n"); } else{ sum=n-next[n]; if(n%sum==0) printf("%ld\n",n/sum);else { printf("1\n"); } } scanf("%s",t); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator