Solution - Codeforces Problem 25A - IQ test

A. IQ test
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
Input
The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Examples
input
5
2 4 7 8 10
output
3
input
4
1 2 1 1
output
2
Click to view Problem Online 

সল্যুশন্সঃ
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int narr[n],odd=0,even=0;
    for(int i=1; i<=n; i++)
    {
        cin >> narr[i];
        if(narr[i]%2 == 0)
        {
            even += 1;
        }else
        {
            odd += 1;
        }
    }

    if(even > odd)
    {
        for(int k=1; k<=n; k++)
        {
            if(narr[k]%2 != 0)
                cout << k << endl;
        }
    }else
    {
        for(int k=1; k<=n; k++)
        {
            if(narr[k]%2 == 0)
                cout << k << endl;
        }
    }
    return 0;
}

আলোচনাঃ

Comments

Popular posts from this blog

Solution - Codeforces Problem 327B - Hungry Sequence

Solution - Timus Problem 1293. Eniya

Solution - Timus Problem 1409. Two Gangsters