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 n, int bob[], int alice[]){sort(alice, alice + n);sort(bob, bob + n);int max1 = alice[n - 1], max2 = bob[n - 1];if (max1 == max2)cout << "Tie\n";else if (max1 > max2)cout << "Alice\n";elsecout << "Bob\n";}int main(){int n = 4;int bob[n] = {5, 6, 3, 1};int alice[n] = {10, 3, 5, 6};war(n, bob, alice);return 0;}
No comments:
Post a Comment