Find the winner in nim | CPP to find nim - game winner ; function to find winner of NIM - game ; case when Alice is winner ; when Bob is winner ; driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; string findWinner ( int A [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res ^= A [ i ] ; if ( res == 0 n % 2 == 0 ) return " Alice " ; else return " Bob " ; } int main ( ) { int A [ ] = { 1 , 4 , 3 , 5 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << " Winner ▁ = ▁ " << findWinner ( A , n ) ; return 0 ; }