codeforces-25A-A. IQ test( C && 怡宝 )

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_16542775/article/details/54232453
A. IQ test
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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
 
         
 
         
题目很简单,就是让你在一群数当中找出唯一一个奇数或者唯一一个偶数......兄台,来瓶怡宝。
 
         
代码如下:
 
         
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n,a[100];
    int EvenSum=1,OddSum=1,EvenCount=0,OddCount=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }

    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            EvenCount++;
            EvenSum+=i;
        }else{
            OddCount++;
            OddSum+=i;
        }
    }
    if(EvenCount>OddCount){
        printf("%d\n",OddSum);
    }else{
        printf("%d\n",EvenSum);
    }

    return 0;
}


 
        

猜你喜欢

转载自blog.csdn.net/qq_16542775/article/details/54232453