Determine winner of the Game by arranging balls in a row | C ++ program for the above approach ; Function to find the winner of the Game by arranging the balls in a row ; Check if small balls are greater or equal to the large ones ; X can place balls therefore scores n - 1 ; Condition if large balls are greater than small ; X can have m - 1 as a score since greater number of balls can only be adjacent ; Compare the score ; Driver Code ; Given number of small balls ( N ) and number of large balls ( M ) ; Function call
#include <iostream> NEW_LINE using namespace std ; void findWinner ( int n , int m ) { int X = 0 ; int Y = 0 ; if ( n >= m ) { X = n - 1 ; Y = m ; } else { X = m - 1 ; Y = n ; } if ( X > Y ) cout << " X " ; else if ( Y > X ) cout << " Y " ; else cout << " - 1" ; } int main ( ) { int n = 3 , m = 1 ; findWinner ( n , m ) ; return 0 ; }