Monday 31 August 2020

War Hacker Earth Solution in C

 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!


https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/warcakewalk/description/


#include<stdio.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
    {
long long int n;
scanf("%lld", &n);
long long int temp, mb=0, ma=0;
for(long long int i=0; i<n; i++)
        {
scanf("%lld", &temp);
            if(mb < temp)
    mb = temp;
}
for(long long int i=0; i<n; i++)
        {
scanf("%lld", &temp);
            if(ma < temp)
    ma = temp;
}

if(mb == ma)
printf("Tie\n");
else if(mb > ma)
printf("Bob\n");
else
printf("Alice\n");
}
return 0;
}

No comments:

Post a Comment