Sum of Two Nim Game

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

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

    cout << "Enter Second Game Piles Number : ";
    cin >> m;

    int p[n+m], xor_sum = 0;

    cout << "Enter First Game Each Piles Stone Number : ";
    for(int i=0; i<n; i++)
    {
        cin >> p[i];
        xor_sum ^= p[i];
    }

    cout << "Enter Second Game Each Piles Stone Number : ";
    for(int i=n; i<n+m; i++)
    {
        cin >> p[i];
        xor_sum ^= p[i];
    }

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

    return 0;
}

Comments