代码如下:
#include<stdio.h>
#include<string.h>
#define MAXN 100
//#define LOCAL //测试,提交时需要删除
char test[MAXN];
int main()
{
int T_min,N_test;
scanf("%d",&N_test);
while(N_test--)
{
scanf("%s",test);
for(int k=1;k<=strlen(test);k++)
{
if(strlen(test)%k!=0) continue; //字符总数为周期的整数倍
int kk=0,tf=1;
if(k==strlen(test))
{
T_min=strlen(test); //周期为字符总数数
break;
}
while(kk<strlen(test)) //遍历字符串
{
for(int kkk=0;kkk<k;kkk++) //遍历周期并判定
{
#ifdef LOCAL //测试
printf("%d,%d,%c,%c\n",k,kk,test[kk+kkk],test[kk+kkk+k]);
#endif
if(test[kk+kkk]!=test[kk+kkk+k])
{
tf=0;
break;
}
}
if(tf&&kk!=strlen(test)-2*k) kk+=k; //需判定遍历终点
else break;
}
if(tf)
{
T_min=k;
break;
}
}
if(N_test) printf("%d\n\n",T_min);
else printf("%d\n",T_min); //最后一行区别输出
}
return 0;
}