周期串 输出串的最小周期

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <math.h>
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     char word[100];
10     scanf("%s",word);
11     int len = strlen(word);
12     for(int i = 1;i <= len;i ++)
13     {
14         if(len % i == 0)
15         {
16             int ok = 1;
17             for(int j = i;j < len;j ++)
18             {
19                 if(word[j] != word[j % i])
20                 {
21                     ok = 0;
22                     break;
23                 }
24             }
25             if(ok)
26             {
27                 printf("%d
",i);
28                 break;
29             }
30         }
31     }
32     return 0;
33 }