poj2406

简单题

#include <iostream>

#include <cstdlib>

#include <cstdio>

#include <cstring>

using namespace std;



#define maxn 1000005



char st[maxn];

int len;



bool ok(int a)

{

    for (int i = a; i < len; i++)

        if (st[i] != st[i % a])

            return false;

    return true;

}



int work()

{

    for (int i = 1; i <= len / 2; i++)

    {

        if (len % i != 0)

            continue;

        if (ok(i))

            return len / i;

    }

    return 1;

}



int main()

{

    while (scanf("%s", st), st[0] != '.')

    {

        len = strlen(st);

        printf("%d\n", work());

    }

    return 0;

}
View Code

 

你可能感兴趣的:(poj)