zoukankan      html  css  js  c++  java
  • poj 2046Power Strings

    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 char str[1000010];
     4 int next[1000010];
     5 int get_next(int x)
     6 {
     7     int i=0,j=-1;
     8     next[0]=-1;
     9     while(i<x)
    10     {
    11         if(j==-1||str[i]==str[j])
    12         {
    13             i++;
    14             j++;
    15             if(str[i]!=str[j])
    16             next[i]=j;
    17             else next[i]=next[j];
    18         }
    19         else j=next[j];
    20     }
    21     return next[x];
    22     
    23 }
    24 int main()
    25 {
    26     int l,len;
    27     while(~scanf("%s",str),str[0]!='.')
    28     {
    29         len=strlen(str);
    30         l=len-get_next(len);
    31         if(len%l) printf("1\n");
    32         else printf("%d\n",len/l);
    33         
    34     }
    35 }

    水题一枚,暴力!

    http://poj.org/problem?id=2406

    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     char str[1000010]; 
     6     char str2[1000010];
     7     int n;//字符串长度 
     8     int i,j,k;//循环子串计数、母串计数器 
     9     while(~scanf("%s",str),str[0]!='.')
    10     {
    11         k=0;
    12         
    13         strcpy(str2,str);
    14         n=strlen(str);
    15         for(i=1;i<=n;i++)//循环节为i 
    16         {
    17             j=0;
    18             if(n%i==0)//不能整除排除 
    19             {
    20                 k=i;
    21                 while(k<n) 
    22                 {
    23                     if(j==i) j=0;
    24                     if(str[k]==str2[j])
    25                     {
    26                         k++;
    27                         j++;
    28                     }
    29                     else break;
    30                 }
    31                 if(k==n) break;
    32             } 
    33         }  
    34         printf("%d\n",n/i);
    35     }
    36 }
  • 相关阅读:
    11111
    单例-Singleton-03
    单例-Singleton-02
    单例-Singleton-01
    load和initialize
    OC中的static-01
    GCD-06
    GCD-05
    GCD-03
    UIView-01
  • 原文地址:https://www.cnblogs.com/1114250779boke/p/2663490.html
Copyright © 2011-2022 走看看