Monday, April 22, 2019

Mahasena.

  • Problem Description

    "Kattapa, as you all know was one of the greatest warriors of his time. The kingdom of Maahishmati had never lost a battle under him (as army-chief), and the reason for that was their really powerful army, also called as Mahasena.
    Kattapa was known to be a very superstitious person. He believed that a soldier is ""lucky"" if the soldier is holding an even number of weapons, and ""unlucky"" otherwise. He considered the army as ""READY FOR BATTLE"" if the count of ""lucky"" soldiers is strictly greater than the count of ""unlucky"" soldiers, and ""NOT READY"" otherwise.
    Given the number of weapons each soldier is holding, your task is to determine whether the army formed by all these soldiers is ""READY FOR BATTLE"" or ""NOT READY"".
    Input
    The first line of input consists of a single integer N denoting the number of soldiers. The second line of input consists of N space separated integers A1, A2, ..., AN, where Ai denotes the number of weapons that the ith soldier is holding.
    "
  • Test Case 1

    Input (stdin)
    4

    11 12 13 14

    Expected Output
    NOT READY
  • Test Case 2

    Input (stdin)
    3

    2 3 4

    Expected Output
    READY FOR BATTLE
Solution

#include<stdio.h>
int main()
{
int a[100], i, n, even, odd;
scanf("%d", &n);
for (i = 0; i<n; i++)
scanf("%d", &a[i]);
even = 0;
odd = 0;
for (i = 0; i < n; i++)
{
if (a[i] % 2 == 0)
even++;
else if (a[i] % 2 != 0)
odd++;
}
if (even>odd)
{
printf("READY FOR BATTLE");

}
else
{
printf("NOT READY");
}

return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...