PROBLEM LINK
Panel Members
Problem Setter: Suhash
Problem Tester:
Editorialist: Sunny Aggarwal
Contest Admin:
Russian Translator:
Mandarin Translator:
Vietnamese Translator:
Language Verifier:
DIFFICULTY:
Cakewalk
PREREQUISITES:
Simple, Input processing, Basic Maths.
PROBLEM:
Given a list of integers. We are asked to report whether the number of even integers is more than the number of odd integers or not.
EXPLANATION
This is a simple problem and can be solved by simply counting the number of even/odd integers.
Basic C++ Code:
int main() { int n; cin >> n; int cnt = 0; for(int i=1; i<=n; i++) { int x; cin >> x; if( x % 2 == 0 ) cnt ++; } puts( cnt > n - cnt ? "READY FOR BATTLE" : "NOT READY" ); return 0; }
Basic Java Code:
public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int cnt = 0; for(int i=1; i<=n; i++) { int x; x = sc.nextInt(); if( x % 2 == 0 ) { cnt ++; } } System.out.println( cnt > n - cnt ? "READY FOR BATTLE" : "NOT READY" ); }
Basic Python Code:
import sys f = sys.stdin n = int(f.readline()) cnt = 0 A = [int(x) for x in f.readline().split()] for i in range(0, n): if A[i] % 2 == 0: cnt += 1 if cnt > n - cnt: print "READY FOR BATTLE" else: print "NOT READY"
TIME COMPLEXITY
O(N)
SPACE COMPLEXITY
O(1)