fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. //implement a hashing vector
  8. int n ; cin>> n ;
  9. vector<int>arr(n);
  10. for(int i = 0 ; i< n ;i++){
  11. cin>>arr[i];
  12. }
  13. int maxi = *max_element(arr.begin(),arr.end());
  14. int mini = *min_element(arr.begin(),arr.end());
  15. vector<int>hash(maxi-mini+1);
  16. for(int i = 0 ; i< n ; i++){
  17. hash[arr[i]-mini]++;
  18. }
  19. int s = hash.size();
  20. for(int i = 0 ; i<s;i++){
  21. if(hash[i]>0) cout<<i+mini<<" "<<hash[i]<<endl;
  22. }
  23. // your code goes here
  24. return 0;
  25. }
Success #stdin #stdout 0s 5320KB
stdin
10
1 2 2 4 4 4 1 6 2000 500
stdout
1 2
2 2
4 3
6 1
500 1
2000 1