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 |
why wa??#include<stdio.h> #include<string.h> char s[1000005]; int next[1000005]; int main() { int i,j,k,len; while(1) { scanf("%s",s+1); if(strcmp(s+1,".") == 0) break; len = strlen(s+1); if(len == 1) { printf("1\n"); continue; } if(len == 2) { if(s[1] == s[2]) printf("2\n"); else printf("1\n"); continue; } next[1] = 0; i = 1;j = 0; while(i < len&&j < len) { if(j == 0||s[i] == s[j]) { i++;j++; next[i] = j; } else j = next[j]; } /// printf("len = %d,j = %d\n",len,j); k = len - j; if(!(len%k)) printf("%d\n",len/k); else printf("1\n"); } return 0; } /* Sample Input abcd aaaa ababab . Sample Output 1 4 3 */ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator