You are not logged in. Please login at www.codechef.com to post your questions!

×

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

This question is marked "community wiki".

asked 17 Nov '15, 03:12

ma5termind's gravatar image

3★ma5termind
1.7k11630
accept rate: 11%

edited 04 Feb '16, 13:13

admin's gravatar image

0★admin ♦♦
19.8k350498541


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"); } }

link

answered 22 Mar '16, 15:55

kumarsanjeet's gravatar image

0★kumarsanjeet
1
accept rate: 0%

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"); } }

link

answered 22 Mar '16, 15:56

kumarsanjeet's gravatar image

0★kumarsanjeet
1
accept rate: 0%

include<iostream>

include<cstring>

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; }

link

answered 21 Jun '16, 18:34

rads_123's gravatar image

1★rads_123
1
accept rate: 0%

include<iostream>

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);

}

link

answered 18 Jul '16, 00:14

vichumon's gravatar image

0★vichumon
1
accept rate: 0%

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

(18 Jul '16, 00:15) vichumon0★

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 "); }

link

answered 27 Jul '16, 22:19

krishna_vamsi's gravatar image

3★krishna_vamsi
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,639
×3,746
×1,173
×170
×52
×1

question asked: 17 Nov '15, 03:12

question was seen: 4,085 times

last updated: 27 Jul '16, 22:19