"Cycle string" NYOJ-1121 cycle string

Source: Internet
Author: User

"topic Link: NYOJ-1121"

Example: ABCABCABC

The length of the string is 9, so the length of the period string Len may be {1,3,9} only, otherwise it will not be possible to form a cycle string.

Next, the comparison is to be made during each week. The description is not clear ... Go through it and understand.

1#include <iostream>2#include <cstring>3 using namespacestd;4 Const intMAXN =202;5 CharS[MAXN];6 intMain () {7      while(Cin >>s)) {    8         intLen =strlen (s);9          for(inti =1; I <= len;i++){            Ten             if(len% i = =0){ One                 intRun =1;  A                  for(intj = I;j < len;j++){ -                     if(S[j]! = s[j%i]) { -Run =0; the                          Break; -                     } -                 } -                 if(run) { +cout << i <<Endl; -                      Break; +                 }     A             }         at         } -memset (s),' /',sizeof(s)); -     } -     return 0;  -}

"Cycle string" NYOJ-1121 cycle string

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.