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 <stdio.h> #include <stdlib.h> #include <string.h> char str [1000010]; int next[1000010]; int getnext() { int i= 0, j= -1; next[0]= -1; while( str[i] ) { if( j== -1 || str[i]== str[j] ) { ++i,++j; next[i]= j; } else j= next[j]; } int len= strlen(str); i= len- j; if( len% i== 0 ) return len/ i; else return 1; } int main() { while( gets( str), str[0]!= '.' ) printf("%d\n", getnext() ); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator