Find the winner of the Game of removing odd or replacing even array elements | C # program for the above approach ; Function to evaluate the winner of the game ; Stores count of odd array elements ; Stores count of even array elements ; Traverse the array ; If array element is odd ; Otherwise ; If count of even is zero ; If count of odd is even ; If count of odd is odd ; If count of odd is odd and count of even is one ; Otherwise ; Driver Code
using System ; class GFG { static void findWinner ( int [ ] arr , int N ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd ++ ; } else { even ++ ; } } if ( even == 0 ) { if ( odd % 2 == 0 ) { Console . WriteLine ( " Player ▁ 2" ) ; } else if ( odd % 2 == 1 ) { Console . WriteLine ( " Player ▁ 1" ) ; } } else if ( even == 1 && odd % 2 == 1 ) { Console . WriteLine ( " Player ▁ 1" ) ; } else { Console . WriteLine ( - 1 ) ; } } public static void Main ( ) { int [ ] arr = { 3 , 1 , 9 , 7 } ; int N = arr . Length ; findWinner ( arr , N ) ; } }