PHOTOGENIC-Editorial

PROBLEM LINK:

Contest

Setter: priyansh2802

Tester: priyansh2802

Editorialist: priyansh2802

DIFFICULTY:

Simple

PREREQUISITES:

Basic observations

PROBLEM:

Nivedita is given the responsibility of arranging all the students in her class in such a manner that the group picture is as photogenic as possible. Some guy gave her an idea that she should first know how many students have Even height and how many students have Odd height since she doesn’t have the time to do the survey you want to help her to accomplish the job.

Your job is to output the number of people whose height is odd and the number of people whose height is odd.

NOTE:-Note that the number of odd height students should be displayed first and the number of even-numbered height students should be displayed after odd-numbered ones

EXPLANATION

As mentioned in the question we need to count the number of odd-numbered height students and even-numbered height students.

The most basic method that we have is making two counters one for odd-numbered height students and one for even height-numbered height students.

The next step is traversing the array.
We know that if any array[i]%2==0 this means that array[i] is even and if array[i]%2!=0, array[i] is odd
Therefore we traverse the array and for each element, we check for the condition above written and increment the odd counter for odd numbers and increment the even counter for the even number
For the output, it is clearly written that Odd counter should be printed first then space and then the even counter should be printed

TIME COMPLEXITY

Time complexity is O(N) for traversing the number of elements in the array.

SOLUTIONS:

Setter's Solution
C++
#include<iostream>
#include<bits/stdc++.h>
#define int long long int
using namespace std;
void solve();
int32_t main(void)
{
    solve();
}
void solve()
{
    int n;
    cin>>n;
    vector<int>a(n);
    int o=0,e=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(auto i:a)
    {
        if(i%2==0)
        {
            e++;
        }
        else
        {
            o++;
        }
    }
    
    cout<<o<<" "<<e<<endl;
 
}