fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. vector<int> a(n);
  8.  
  9. for (int i = 0; i < n; i++) {
  10. cin >> a[i];
  11. }
  12. int max_val = *max_element(a.begin(), a.end());
  13. vector<int> res(max_val + 1, 0);
  14.  
  15. for (int i = 0; i < n; i++) {
  16. res[a[i]]++;
  17. }
  18.  
  19. int c = 0;
  20. for (int i = 0; i < res.size(); i++) {
  21. if (res[i] > 0) c++;
  22. }
  23.  
  24. cout << c << endl;
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5284KB
stdin
5
2 2 3 3 4
stdout
3