UESTC--1682

原题链接:

分析:求最小周期的应用。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<algorithm>
 5 #define maxn 1005
 6 using namespace std;
 7 char s[maxn];
 8 int next[maxn],len;
 9 void get_next()
10 {
11     int i=0,j=-1;len=strlen(s);
12     next[0]=-1;
13     while(i<len)
14     {
15         if(j==-1||s[i]==s[j]){
16             i++,j++;
17             next[i]=j;
18         }
19         else j=next[j];
20     }
21 }
22 int main()
23 {
24     int T;scanf("%d",&T);
25         while(T--)
26         {
27          scanf("%s",s);
28              get_next();
29              if(len%(len-next[len]))puts("1");
30                  else printf("%d\n",len/(len-next[len]));
31          }
32         return 0;
33 }
View Code

 

posted @ 2013-09-08 19:21  EtheGreat  阅读(143)  评论(0编辑  收藏  举报