赞
踩
201312-1 出现次数最多的数
哈希
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 10010; int n; int cnt[N]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); cnt[x]++; } int max_i = 0; for (int i = 1; i < N; ++i) if (cnt[i] > cnt[max_i]) max_i = i; printf("%d", max_i); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。