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 <iostream> #include <cstdio> #include <cstring> using namespace std; int next[1000000], len; char a[1000000]; int main() { next[0] = -1; while (gets(a), strcmp(a, ".")) { len = strlen(a); for (int i = 1, j = -1; i < len; ++i) { while (j >= 0 && a[j+1] != a[i]) j = next[j]; next[i] = (j = j + (a[j+1] == a[i])); } if (len % (len - 1 - next[len-1])) puts("1"); else printf("%d\n", len / (len - 1 - next[len-1])); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator