首页 > 其他 > 详细

[code]判断周期串

时间:2016-03-16 22:11:48      阅读:159      评论:0      收藏:0      [点我收藏+]
技术分享
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
#include<string.h>
int main()
{
        char word[100];
       scanf"%s",word);
        int len=strlen(word);
        for(int i=1;i<=len;i++)
               if(len%i==0)
              {
                      int ok=1;
                      for(int j=i;j<len;j++)
                            if(word[j]!=word[j%i])
                           {
                                  ok=0; break;
                           }
                      if(ok){printf("%d\n" ,i);break;}
              }
        return 0;
}

//两层for循环,
第一层是字符串周期数的循环,从1:到字符串总长
第二层以上一层确定的周期数,找到第二个周期往后的字符串依次比较,是否相等

[code]判断周期串

原文:http://www.cnblogs.com/zhxshseu/p/5285210.html

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