Poj1961period "KMP Next Array"

Source: Internet
Author: User

The main idea: the same problem with poj2406 see http://www.cnblogs.com/zhanzhao/p/4761477.html

Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intMAXN =1000005;7 8 intNEXT[MAXN];9 Ten void Get(Char*s) { One     intL =strlen (s); A     intj =0, k =-1; -next[0] = -1; -      while(J <l) { the         if(k = =-1|| S[J] = =S[k]) { -              -  -  + //if (s[++j] = = S[++k]) { - //Next[j] = next[k]; + //} else { A //next[j] = k; at //            } -NEXT[++J] = + +K; -}Else { -K =Next[k]; -         } -     } in } - CharS[MAXN]; to  + intMain () { -     intN; the     intKase =1; *      while(SCANF ("%d", &n) &&N) { $scanf"%s", s);Panax Notoginsengprintf"Test Case #%d\n", kase++); -         Get(s); the         intL =strlen (s); + //for (int i = 0; I <= l; i++) { A //printf ("%d", Next[i]); the //}puts (""); +          for(inti =2; I <= l; i++) { -             intAns =1; $             if(i% (i-next[i]) = =0) { $Ans = I/(i-next[i]); -             } -             if(Ans >1) { theprintf"%d%d\n", I, ans); -             }Wuyi         } thePuts""); -     } Wu}
View Code

Poj1961period "KMP Next Array"

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.