CSP认证201312-1出现次数最多的数[C++题解]:简单题
生活随笔
收集整理的這篇文章主要介紹了
CSP认证201312-1出现次数最多的数[C++题解]:简单题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 題目解答
- 題目鏈接
題目解答
來源:acwing
分析:使用hash表,統計出現的次數即可。
ac代碼
#include<bits/stdc++.h> using namespace std; const int N = 1010; int n; unordered_map<int,int> mp; int main(){cin >> n;int x;while(n--){scanf("%d",&x);mp[x]++;}int maxn = -1,res = 1e6;for(auto item : mp){if(item.second > maxn){maxn = item.second;res = item.first;}if(item.second == maxn && item.first < res) res = item.first;}cout << res<<endl;}題目鏈接
https://www.acwing.com/problem/content/3195/
總結
以上是生活随笔為你收集整理的CSP认证201312-1出现次数最多的数[C++题解]:简单题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CSP认证202012-1期末预测之安全
- 下一篇: CSP认证201312-2 ISBN号码