Sample Input

abcd
aaaa
ababab
.
Sample Output

1 //1个abcd
4 //4个a
3 //3个ab

 

 

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<string.h>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 const int MAXN=1000010;
 8 char T[MAXN];
 9 int next[MAXN];
10 int n;
11 void getNext()
12 {
13     int j,k;
14     j=0;
15     k=-1;
16     next[0]=-1;
17     while(j < n)
18     {
19         if(k==-1||T[j]==T[k])
20         {
21             j++;
22             k++;
23            
24             next[j]=k;
25         }
26         else k=next[k];
27         
28         
29     }
30     if(n%(n-k)==0)
31         printf("%d\n",n/(n-k));
32     else
33         printf("1\n") ;
34 }
35 int main()
36 {
37    
38    
39     while(scanf("%s",&T) != EOF)
40     {    
41         if (T[0]=='.')
42            break ;
43         n = strlen(T) ;
44         getNext();
45         
46     }
47     return 0;
48 }
View Code

相关文章:

  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2022-01-17
  • 2021-11-08
  • 2021-07-09
  • 2021-07-22
相关资源
相似解决方案