fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool my(pair <const int, int> a, pair <const int, int> b) {
  5. if (a.second < b.second) {
  6. return false;
  7. }
  8.  
  9. return true;
  10. }
  11.  
  12. int main() {
  13. cin.tie(0);
  14. ios::sync_with_stdio(false);
  15.  
  16. freopen("input.txt", "r", stdin);
  17. freopen("output.txt", "w", stdout);
  18.  
  19. int n = 8;
  20. vector <int> a = {4, 2, 3, 4, 5, 6, 7, 1};
  21.  
  22. unordered_map <int, int> vl;
  23.  
  24. for (int i : a) {
  25. if (!vl[i]) {
  26. vl[i] = 1;
  27. } else {
  28. vl[i] += 1;
  29. }
  30.  
  31. }
  32.  
  33. // sort(vl.begin(), vl.end(), my);
  34.  
  35.  
  36. for (auto i : vl) cout << i.first << ": " << i.second << "\n";
  37. return 0;
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty