Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

发个简短一点的代码

Posted by buaabarty at 2012-09-02 15:31:08 on Problem 2406
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator