Periodic string problems

Source: Internet
Author: User

#include "OJ.h" #include <iostream>using namespace  std;/* function: Calculates the minimum period of a string. Prototype:    int getminperiod (char *string); input parameter:    char * string: String. return value:    int string minimum period. Idea: Use I to denote a possible period of a string, starting from a period of 1 to gradually increase by 1, when I meet the period of the string is returned; I satisfy the condition that is the period of the string: 1, save the first I character, all the strings are compared with the string, no different characters   2, The length of all strings K is an integer multiple of I */int getminperiod (char *inputstring) {/    * here implements the function */if (inputstring = NULL | | *inputstring = = ')} { return 0;} for (int i =1; I <=100; ++i) {//char *p = Inputstring;char *temp = new Char [i];bool flag = false;for (int j =0; J < I ++J) {Temp[j] = inputstring[j];} int k = i; while (inputstring[k]! = ' + ') {if (temp[k%i]! = Inputstring[k]) {flag =true;break;} k++;} Delete [] temp;if (flag = = False && k%i = = 0) {return i;}}    return 0;} int main () {char inputstring[13] = "ABCABCABCABC"; Cout<<getminperiod (inputstring) <<endl;return 0;}

Periodic string problems

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.