CodeForces-25A
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
问题简述:
给出一组数字,这组数字保证会有与其它数字均匀度不同的数,即如果一串数字里前只会出现一个偶数,或者单数,我们需要找出这个不一样的数并且输出它的序号。
问题分析:
用一个数组接收这组数字,并且用循环遍历整个数组,当当前数字为偶数是,令一个计数加一,当为奇数时,另另一个计数加一并且将当前序号记录下来。最后比较两个计数,小的肯定是唯一的那个特殊数字,输出记下的记号即可。
AC代码:
#include<iostream>
using namespace std;
int main1()
{
int n, a[200],i,flag=0,flag1=0,count=0,count1=0;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = 0; i < n; i++)
{
if (a[i] % 2 == 0)
{
count++;
flag = i;
}
else
{
count1++;
flag1 = i;
}
}
if (count > count1)
cout << flag1 + 1 << endl;
else
cout << flag + 1 << endl;
return 0;
}