fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, a[100005], b[1000006];
  6.  
  7. int main(){
  8. cin >> n;
  9. for(int i = 1; i <= n; i++){
  10. cin >> a[i];
  11. }
  12. for(int i = 1; i <= n; i++){ // duyệt từng phần tử của a
  13. int j = a[i] + 100000; // Do a[i] có thể âm, nên thay vì đếm
  14. // a[i] thông thường, ta đếm a[i] + 10^5 để
  15. // luôn nhận được giá trị dương
  16. b[j]++; // Đếm số lần xuất hiện
  17. }
  18. int so_lan_xh_nhieu_nhat = 0;
  19. for(int i = 1; i <= n; i++){
  20. int j = a[i] + 100000;
  21. if(b[j] > so_lan_xh_nhieu_nhat){
  22. so_lan_xh_nhieu_nhat = b[j];
  23. }
  24. }
  25. // Thêm 1 lần duyệt nữa để có thể tìm được số lớn nhất và xuất hiện nhiều nhất
  26. int ans = -100000;
  27. for(int i = 1; i <= n; i++){
  28. int j = a[i] + 100000;
  29. if(b[j] == so_lan_xh_nhieu_nhat){
  30. ans = max(ans, j - 100000);
  31. }
  32. }
  33. cout << ans;
  34. }
  35.  
  36.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
-100000