Number of ways to erase exactly one element in the Binary Array to make XOR zero | C ++ program to find the number of ways to erase exactly one element from this array to make XOR zero ; Function to find the number of ways ; Calculate the number of 1 ' s ▁ and ▁ 0' s ; Considering the 4 cases ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int no_of_ways ( int a [ ] , int n ) { int count_0 = 0 , count_1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) count_0 ++ ; else count_1 ++ ; } if ( count_1 % 2 == 0 ) return count_0 ; else return count_1 ; } int main ( ) { int n = 4 ; int a1 [ 4 ] = { 1 , 1 , 0 , 0 } ; cout << no_of_ways ( a1 , n ) << endl ; n = 5 ; int a2 [ 5 ] = { 1 , 1 , 1 , 0 , 0 } ; cout << no_of_ways ( a2 , n ) << endl ; n = 5 ; int a3 [ 5 ] = { 1 , 1 , 0 , 0 , 0 } ; cout << no_of_ways ( a3 , n ) << endl ; n = 6 ; int a4 [ 6 ] = { 1 , 1 , 1 , 0 , 0 , 0 } ; cout << no_of_ways ( a4 , n ) << endl ; return 0 ; }