ZOJ - 2132 The Most Frequent Number 计数

#include<bits/stdc++.h>
using namespace std;
const int maxn = 10 + 3;
typedef long long ll;

int n, a;
map<int, int> mp;

int main() {
    while(~scanf("%d", &n) && n) {
        mp.clear(); int ans, cnt = 0;
        for(int i = 0; i < n; ++i) {
            scanf("%d", &a);
            mp[a]++;
            if(mp[a] > cnt) { cnt = mp[a]; ans = a; }
        }
        printf("%d\n", ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xiang_6/article/details/79728131