201312-1 出现次数最多的数
实现
#include <iostream>
#define MAXN 0x2f00
unsigned int num_cnt[MAXN];
int main() {
int sum;
std::cin >> sum;
int i,max_cnt = 0,ans_num = 0;
for (i = 0;i < sum;++i) {
int num;
std::cin >> num;
++num_cnt[num];
if (num_cnt[num] > max_cnt) {
max_cnt = num_cnt[num];
ans_num = num;
} else if (num_cnt[num] == max_cnt && ans_num > num) {
ans_num = num;
}
}
std::cout << ans_num;
}