Find the winner of a game of donating i candies in every i | C ++ Program for the above approach ; Function to find the winning player in a game of donating i candies to opponent in i - th move ; Steps in which number of candies of player A finishes ; Steps in which number of candies of player B finishes ; If A 's candies finishes first ; Otherwise ; Driver Code ; Candies possessed by player A ; Candies possessed by player B
#include <bits/stdc++.h> NEW_LINE using namespace std ; int stepscount ( int a , int b ) { int chanceA = 2 * a - 1 ; int chanceB = 2 * b ; if ( chanceA < chanceB ) { cout << " B " ; } else if ( chanceB < chanceA ) { cout << " A " ; } return 0 ; } int main ( ) { int A = 2 ; int B = 3 ; stepscount ( A , B ) ; return 0 ; }