ZOJ1905只要注意一个点就行了,题目意思是求长度与周期的比值

View Code
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 #define N 1000001
 5 
 6 char s[N];
 7 int main()
 8 {
 9      int i, j, len,ok;
10      
11      while(scanf("%s",s)!=EOF && strcmp(s,"."))
12      {
13          len = strlen(s);
14          for(i=1; i<=len; i++)
15          {
16             if(len%i == 0)
17             {
18                 ok = 1;
19                 for(j=i; j<len; j++)
20                 {
21                     if(s[j] != s[j%i])
22                     {
23                         ok = 0;
24                         break;
25                     }
26                 }
27                 if(ok)
28                 {
29                     printf("%d\n",len/i);
30                     break;
31                 }
32             }
33          }
34      }
35      system("pause");
36    return 0;
37 }
posted @ 2012-04-25 08:33  zhongya  阅读(241)  评论(0编辑  收藏  举报