Staircase Nim Game

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;

    cout << "Enter Number of Stair : ";
    cin >> n;

    int a[n+1], xor_sum = 0;

    cout << "Enter Number of Coin for Each Stair : ";
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];

        if(i%2 == 1)
            xor_sum ^= a[i];
    }

    if(xor_sum > 0)
        cout << "First Player Win." << "\n";
    else
        cout << "Second Player Win." << "\n";

    return 0;
}

Comments