Misere Nim Game

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;

    cout << "Enter Piles Number : ";
    cin >> n;

    int a[n], xor_sum = 0, one = 0;

    cout << "Enter Each Pile Stone Number : ";
    for(int i=0;i<n;i++)
    {
        cin >> a[i];

        if(a[i] == 1)
            one++;

        xor_sum ^= a[i];
    }

    if(n == one && n%2 == 0)
        cout << "First Player Win." << "\n";

    else if(n == one && n%2 == 1)
        cout << "Second Player Win." << "\n";

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

    else
        cout << "Second Player Win." << "\n";

    return 0;
}

Comments