Skip to content

Commit

Permalink
Mahasena Problem Solved of CodeChef
Browse files Browse the repository at this point in the history
  • Loading branch information
saumil92001 committed Oct 21, 2021
1 parent 0db551f commit a0163c5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Code chef/Mahasena/Question.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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".

Note: You can find the definition of an even number here

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).
1 change: 1 addition & 0 deletions Code chef/Mahasena/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.codechef.com/problems/AMR15A
26 changes: 26 additions & 0 deletions Code chef/Mahasena/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
using namespace std;

string getResult(int arr[],int num){
int oddCounter=0,evenCounter=0;
for(int j=0;j<num;++j){
if(arr[j]%2==0){
++evenCounter;
}
else{
++oddCounter;
}
}
return evenCounter>oddCounter?"READY FOR BATTEL":"NOT READY";
}

int main(){
int num;
cin>>num;
int arr[num];
for(int i=0;i<num;++i){
cin>>arr[i];
}
cout<<getResult(arr,num);
return 0;
}

0 comments on commit a0163c5

Please sign in to comment.