War

Alice and Bob are playing the legendary game of Age of Empires. They are trying extremely hard to be strategic, and smart - but are failing to do so. They’re newbies at the game and are just learning the parts of the game.

They don’t have an idea about the strength and weaknesses of various units in the game. So, they start creating random units based on how good cool they look to them. But, that’s a terrible strategy in the battlefield of the Age of Empires.

To play a fair game, both Alice and Bob generate the same number of units, N. We’re given two arrays representing the strength of the units of both of their armies. The first array represents Bob’s army, the second one represents Alice’s army.

Now, the fight begins. But, how does one come to know who wins? Simple way actually. Every soldier in either army starts going on a rampage and starts killing every soldier of the opposite army, which has less strength. The army which destroys the other army wins the war and wins the game between two newbies. If such a case is not possible, the result will thus be a TIE!

Help yourself to find the result of the game!

Example:

Input:  n = 4, bob = [5,6,3,1], alice = [10,3,5,6]
Output: Alice

Approach

C++

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

void war(int nint bob[], int alice[])
{
    sort(alicealice + n);
    sort(bobbob + n);
    int max1 = alice[n - 1], max2 = bob[n - 1];
    if (max1 == max2)
        cout << "Tie\n";
    else if (max1 > max2)
        cout << "Alice\n";
    else
        cout << "Bob\n";
}
int main()
{
    int n = 4;

    int bob[n] = {5631};
    int alice[n] = {10356};

    war(nbobalice);

    return 0;
}


No comments:

Post a Comment