Find the winner of a game where scores are given as a binary string | C # program for predicting winner ; function for winner prediction ; increase count ; check losing condition ; check winning condition ; check tie on n - 1 point ; increase count ; check for 2 point lead ; condition of lost ; condition of win ; Driver Code
using System ; class GFG { public static void predictWinner ( string score , int n ) { int [ ] count = new int [ 2 ] ; int i ; for ( i = 0 ; i < score . Length ; i ++ ) { count [ score [ i ] - '0' ] ++ ; if ( count [ 0 ] == n && count [ 1 ] < n - 1 ) { Console . Write ( " GEEKS ▁ lost " ) ; return ; } if ( count [ 1 ] == n && count [ 0 ] < n - 1 ) { Console . Write ( " GEEKS ▁ won " ) ; return ; } if ( count [ 0 ] == n - 1 && count [ 1 ] == n - 1 ) { count [ 0 ] = 0 ; count [ 1 ] = 0 ; break ; } } for ( i ++ ; i < score . Length ; i ++ ) { count [ score [ i ] - '0' ] ++ ; if ( Math . Abs ( count [ 0 ] - count [ 1 ] ) == 2 ) { if ( count [ 0 ] > count [ 1 ] ) { Console . Write ( " GEEKS ▁ lost " ) ; } else { Console . Write ( " GEEKS ▁ won " ) ; } return ; } } } public static void Main ( string [ ] args ) { string score = "1001010101111011101111" ; int n = 15 ; predictWinner ( score , n ) ; } }