AMR15A - Editorial

PROBLEM LINK

Practice
Contest

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)

SIMILAR PROBLEMS

Distinct Codes

Black And White Cells

Chef And Easy Problem

import java.io.*;
public class in
{
public static void main(String args[])throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
int n,a,i,j=0,c=0;
n=Integer.parseInt(buf.readLine());
for(i=0;i<n;i++)
{
a=Integer.parseInt(buf.readLine());
if(a%2==0)
c++;
else
j++
}
if(c>b)
System.out.println(“READY FOR BATTLE”);
else
System.out.println(“NOT READY”);
}
}

import java.io.*;
public class in
{
public static void main(String args[])throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
int n,a,i,j=0,c=0;
n=Integer.parseInt(buf.readLine());
for(i=0;i<n;i++)
{
a=Integer.parseInt(buf.readLine());
if(a%2==0)
c++;
else
j++
}
if(c>b)
System.out.println(“READY FOR BATTLE”);
else
System.out.println(“NOT READY”);
}
}

#include
#include
using namespace std;
int main()
{
int n,ev=0,od=0;
int a[100];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]%2==0)
ev++;
else
od++;
}
if(ev>od)
cout<<“READY FOR BATTLE”;
else
cout<<“NOT READY”;
return 0;
}

#include

using namespace std;

int main()

{

int a[100],n,i,ev,od;

ev=0;

ev=0;

cin>>n;

for(i=0;i<n;i++)

{

cin>>a[i];

}

for(i=0;i<n;i++)

{

if((a[i]%2)==0)

{

ev++;

}

else

{

od++;

}

}

if(ev>od)

{

cout<<“READY FOR BATTLE”;

}

else

{

cout<<“NOT READY”;

}
return (0);

}

whats wrong with this code? why is it not entering the loop?
#include<stdio.h>
void main()
{
int N,i,b=0;
int A[100];
scanf("%d",&N);
for(i=1;i<=N;i++)
{
scanf("%d",&A[i]);
}
for(i=1;i<=N;i++)
{
if(A[i]%2==0)
b=b+1;
}
if(b>N-b)
printf(" ready for battle");
else
printf("not ready ");
}

what is the error ? The external compiler show correct results but the problem answer doesnt match. Please help

solution
- YouTube

Why there is no c# Compiler for this problem?
Is it a bug in CodeChef?

your indexing array from i=1, which is wrong. you need to index it from i=0.