POJ2406

//题意:寻找最小周期子串,结果就是字符串长度len除以子串长度

//

//

/*source:
*idea from:
*date: 8-21-2015
*/

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
#define LL long long
#define UI unsigned int
#define MAX 1000000+10
#define MOD 1000000007
#define INF 1<<30

char s[MAX], sub[MAX];


int main()
{
//freopen("1009.in", "r", stdin);
//freopen("result.out", "w", stdout);

int i, j, k, m;
int len;
int ans;
bool ok;

while(scanf("%s", s), strcmp(s, "."))
{
len = strlen(s);
ans = 1;
if(len == 1) {}
else
{
for(i = 1; i <= len/2; i++)
{
if(len%i == 0)
{
ok = true;
strncpy(sub, s, i);
for(j = 0; j < len; j += i)
{
for(k = j, m = 0; k < j+i; k++, m++)
{
if(sub[m] != s[k])
{
ok = false;
break;
}
}
if(!ok) break;
}
if(ok)
{
ans = len/i;
break;
}
}
}
}
printf("%d\n", ans);
}



return 0;
}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页