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

    类似于1961题,不过比1961要简单,只是让求最长的前缀,要注意它要求输入"."时表示输入结束。

    代码:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int next[1000005];
    char str[1000005];
    
    void init()
    {
        int i,j;
    
        i=0;j=-1;
        next[0]=-1;
        while(str[i]!='\0')
        {
            if(j == -1 || str[i] == str[j])
            {
                i++;j++;
                next[i] = j;
            }
            else
            j = next[j];
        }
    }
    
    int main()
    {
        //int i,maxx;
    
        while(scanf("%s",str) != EOF)
        {
            getchar();
            int len = strlen(str);
            if(len==1 && str[0]=='.')
            break;
            init();
            if(len%(len-next[len]) == 0 )
            printf("%d\n",len/(len-next[len]));
            else
            printf("1\n");
        }
        return 0;
    }
  • 相关阅读:
    Graphic
    GUI编程实战
    Swing 混合布局
    运算符与数据库函数
    mysq基础操作
    mysql常见问题处理
    static 与final abstract关键字
    JAVA面试
    Swing
    AWT的应用
  • 原文地址:https://www.cnblogs.com/misty1/p/2468861.html
Copyright © 2011-2022 走看看