POJ Brush Questions (2406)

Source: Internet
Author: User

Program (already accepted):

#include <stdio.h> #include <string.h> #include <memory.h> #define N 1000010char str[n];int next[n]; int Get_next (char pattern[], int next[]) {    int j=0,k=-1;    int Len=strlen (pattern);    Next[0]=-1;    while (J<len)    {        if (k==-1| | Pattern[j]==pattern[k])            next[++j]=++k;        else            k=next[k];    }    j=len-k;//if the last position does not match, it will roll to the len-k position, which is the length of the minimum repeating string.    if (len%j==0)        return len/j;    else        return 1;} int main () {while    (scanf ("%s", str), str[0]!= '. ')    {        printf ("%d\n", Get_next (str, next));    }    return 0;} </span><strong style= "FONT-SIZE:18PX; Color:rgb (0, 0, 153); " ></strong>

Run Time:



The subject is still of great value:

1. The flexible application of KMP algorithm is investigated.

2. Because the 1000010*4 (int) will exceed the stack space (1M), the program crashes, so it can only do global variables.

POJ Brush Questions (2406)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.