题目:
在一堆只有奇数和偶数的数字里面输出与其他数字不同的数字,不同的数只出现过一次。
题解:
数清奇数和偶数哪个多,然后再进行输出性质不同的数字
代码:
#include<iostream>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int N = 101;
int a[N];
int main()
{
int n; cin >> n; int cnt_ou = 0, cnt_ji = 0;
for (int i = 0; i < n; i++) { //判断奇偶数哪个多
cin >> a[i];
if (a[i] % 2 == 0) {
cnt_ou++;
}
else {
cnt_ji++;
}
}
if (cnt_ji > cnt_ou) {
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 0) {
cout << i + 1;
break;
}
}
}
else {
for (int i = 0; i < n; i++) {
if (a[i] % 2 != 0) {
cout << i + 1;
break;
}
}
}
return 0;
}