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: using System ; class GFG { static string ReverseComplement ( char [ ] s , int n , int k ) { int rev = ( k + 1 ) / 2 ; int complement = k - rev ; if ( rev % 2 == 1 ) s = reverse ( s ) ; if ( complement % 2 == 1 ) { for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '0' ) s [ i ] = '1' ; else s [ i ] = '0' ; } } return ( new string ( s ) ) ; } static char [ ] reverse ( char [ ] a ) { int i , n = a . Length ; char t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } public static void Main ( ) { string str = "10011" ; int k = 5 ; int n = str . Length ; Console . Write ( ReverseComplement ( str . ToCharArray ( ) , n , k ) ) ; } }