频繁元素 C++
频繁元素
https://ac.nowcoder.com/acm/problem/22229
#include <iostream> using namespace std; int a[25]; int main(){ int n, t, mf = 0, mv, cnt; cin >> n; for(int i = 0; i < n; ++i){ cin >> a[i]; } for(int i = 0; i < n; ++i){ cnt = 0; for(int j = 0; j < n; ++j){ if(a[j] == a[i]) ++cnt; } if(cnt > mf) mf = cnt, mv = a[i]; } cout << mv; return 0; }