题目链接:http://www.codeforces.com/problemset/problem/25/A
题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数。
C++代码:


#include <iostream> using namespace std; const int maxn = 110; int a, n, x = -1, y = -1; int main() { cin >> n; for (int i = 1; i <= n; i ++) { cin >> a; if (a % 2 == 0) x = (x == -1) ? i : -2; else y = (y == -1) ? i : -2; } cout << x + y + 2; return 0; }
CodeForces A题速解
本文介绍了一个CodeForces A级题目——寻找一个数组中唯一一个奇偶性与众不同的数字,并提供了一段简洁高效的C++代码实现。该算法通过遍历数组并利用两个变量跟踪奇数和偶数的位置来解决此问题。

被折叠的 条评论
为什么被折叠?



