杭电1029 http://acm.hdu.edu.cn/showproblem.php?pid=1029
题目大意:求一组数中正好出现了(n + 1) / 2次的数字。
解题思路:一开始看错了。。以为求最大的那个呢。
AC代码:
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e7 + 5;
int num[maxn];
int n;
int a;
int ans;
int maxx;
int main() {
while(cin >> n) {
//maxx = (1 + n) / 2;
for (int i = 0; i < n; i++) {
cin >> num[i];
}
sort(num, num + n);
cout << num[(n + 1) / 2] << endl;
}
return 0;
}