Count minimum bits to flip such that XOR of A and B equal to C | C ++ code to count the Minimum bits in A and B ; If both A [ i ] and B [ i ] are equal ; If Both A and B are unequal ; Driver Code ; N represent total count of Bits
#include <bits/stdc++.h> NEW_LINE using namespace std ; int totalFlips ( char * A , char * B , char * C , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; ++ i ) { if ( A [ i ] == B [ i ] && C [ i ] == '1' ) ++ count ; else if ( A [ i ] != B [ i ] && C [ i ] == '0' ) ++ count ; } return count ; } int main ( ) { int N = 5 ; char a [ ] = "10100" ; char b [ ] = "00010" ; char c [ ] = "10011" ; cout << totalFlips ( a , b , c , N ) ; return 0 ; }