然后用了之前kmp的一个思想
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 100
char s[maxn];
int Next[maxn];
void GetNext(char *p)
{
int k=-1;
Next[0]=-1;
int slen=strlen(p);
int i=0;
while(i<slen)
{
if(k==-1||p[k]==p[i])
{
k++;
i++;
Next[i]=k;
}
else
k=Next[k];
}
}
int main()
{
int T;
scanf("%d",&T);
int n;
while(T--)
{
scanf("%s",s);
GetNext(s);
int slen=strlen(s);
int h=slen-Next[slen];
if(Next[slen]%h==0)
printf("%d\n",h);
else
printf("%d\n",slen);
if(T>=1)
printf("\n");
}
return 0;
}