首页 > 其他 > 详细

周期串 输出串的最小周期

时间:2015-11-19 09:30:57      阅读:260      评论:0      收藏:0      [点我收藏+]
 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\n",i);
28                 break;
29             }
30         }
31     }
32     return 0;
33 }

 

周期串 输出串的最小周期

原文:http://www.cnblogs.com/banshaohuan/p/4976531.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!