原题链接:http://poj.org/problem?id=2406

分析:求最小周期。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<algorithm>
 5 #define maxn 1000005
 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     while(gets(s)&&s[0]!='.')
25     {
26         get_next();
27         if(len%(len-next[len]))puts("1");
28         else printf("%d\n",len/(len-next[len]));
29     }
30     return 0;
31 }
View Code

相关文章:

  • 2021-10-14
  • 2022-01-23
  • 2021-08-12
  • 2022-01-18
  • 2022-01-14
  • 2021-10-03
  • 2021-09-24
猜你喜欢
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-06-23
  • 2021-08-13
相关资源
相似解决方案