hdu 1358 Period

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358

题目大意:解释一下输出数据,

第一组:

2  2 表示的是第一个字母到第二字母,a出现了两次。

3  3 表示的是第一个字母到第三个字母,a出现了3次。

第二组:

2 2表示的是第一个字母到第二个字母,a出现了两次。
6 2表示的是第一个字母到第六个字母,aab出现了两次。
9 3表示的是第一个字母到第九个字母,aab出现了三次。
12 4表示的是第一个字母到第十二个字母,aab出现了四次。
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 
 5 using namespace std;
 6 
 7 int next[1000010];
 8 char str[1000010];
 9 
10 void get_next()
11 {
12     int i=0,j=-1;
13     next[0]=-1;
14     int lens=strlen(str);
15     while (i<lens)
16     {
17         if (j==-1||str[i]==str[j])
18         {
19             i++;
20             j++;
21             next[i]=j;
22             if (i>=2&&j>=1)
23             {
24                 if (i%(i-next[i])==0)
25                 {
26                     int k=i/(i-next[i]);
27                     printf ("%d %d
",i,k);
28                 }
29             }
30         }
31         else
32             j=next[j];
33     }
34 }
35 int main ()
36 {
37     int n,flag=1;
38     while (scanf("%d",&n),n)
39     {
40         getchar();
41         scanf("%s",str);
42         printf ("Test case #%d
",flag++);
43         get_next();
44         printf ("
");
45         //lens=strlen(str);
46     }
47     return 0;
48 }
原文地址:https://www.cnblogs.com/qq-star/p/3888641.html