Periodic Binary String With Minimum Period and a Given Binary String as Subsequence . | C ++ implementation to find the periodic string with minimum period ; Function to find the periodic string with minimum period ; Print the string S if it consists of similar elements ; Find the required periodic string with period 2 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findPeriodicString ( string S ) { int l = 2 * S . length ( ) ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S [ i ] == '1' ) count ++ ; } if ( count == S . length ( ) count == 0 ) cout << S << " STRNEWLINE " ; else { char arr [ l ] ; for ( int i = 0 ; i < l ; i += 2 ) { arr [ i ] = '1' ; arr [ i + 1 ] = '0' ; } for ( int i = 0 ; i < l ; i ++ ) cout << arr [ i ] ; cout << " STRNEWLINE " ; } } int main ( ) { string S = "1111001" ; findPeriodicString ( S ) ; return 0 ; }