Navbar menu

CodeChef - Python Practice Solution - Mahasena

Problem:
  • 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 mighty 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.
Output:
  • Generate one line output saying "READY FOR BATTLE" if the army satisfies the conditions that Kattapa requires or "NOT READY" otherwise (quotes for clarity).
Constraints:
  • 1 ≤ N ≤ 100
  • 1 ≤ Ai ≤ 100
Example 1:

# Input
1 1

# Output
NOT READY

Example 2:

# Input
1 2

# Output
READY FOR BATTLE

Explanation

Example 1:
  • For the first example, N = 1 and the array A = [1]. There is only 1 soldier and he is holding 1 weapon, which is odd. The number of soldiers holding an even number of weapons = 0, and the number of soldiers holding an odd number of weapons = 1. Hence, the answer is "NOT READY" since the number of soldiers holding an even number of weapons is not greater than the number of soldiers holding an odd number of weapons.
Example 2:
  • For the second example, N = 1 and the array A = [2]. There is only 1 soldier holding 2 weapons, which is even. The number of soldiers holding an even number of weapons = 1, and the number of soldiers holding an odd number of weapons = 0. Hence, the answer is "READY FOR BATTLE" since the number of soldiers holding an even number of weapons is greater than the number of soldiers holding an odd number of weapons.
Solution:

N =int(input())
A = list(map(int,input().split()))

odd = 0
even = 0
for i in range(0,N):
    if A[i]%2 == 0:
        even += 1
    else:
        odd += 1

if even > odd:
    print("READY FOR BATTLE")
else:
    print("NOT READY")
Note: The problem statement is given by codechef.com but the solution is generated by the Geek4Tutorial admin. We highly recommend you solve this on your own, however, you can refer to this in case of help. If there is any concern regarding this post or website, please contact us using the contact form. Thank you!

No comments:

Post a Comment