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. // 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
  19. int ans = 0;
  20. for(int i = 0; i <= 200000; i++){
  21. if(b[i] > 2) ans++;
  22. }
  23. cout << ans;
  24. }
  25.  
  26.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty