text: String obtained by reversing and complementing a Binary string K times | C ++ program to perform K operations upon the string and find the modified string ; Function to perform K operations upon the string and find modified string ; Number of reverse operations ; Number of complement operations ; If rev is odd parity ; If complement is odd parity ; Complementing each position ; Return the modified string ; Driver Code ; Function call
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; string ReverseComplement ( string s , int n , int k ) { int rev = ( k + 1 ) / 2 ; int complement = k - rev ; if ( rev % 2 ) reverse ( s . begin ( ) , s . end ( ) ) ; if ( complement % 2 ) { for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '0' ) s [ i ] = '1' ; else s [ i ] = '0' ; } } return s ; } int main ( ) { string str = "10011" ; int k = 5 ; int n = str . size ( ) ; cout << ReverseComplement ( str , n , k ) ; return 0 ; }