fork download
  1.  
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. bool cmp(pair<int, int> a, pair<int, int> b) {
  7. if (a.second == b.second)
  8. return a.first < b.first;
  9. return a.second > b.second;
  10. }
  11.  
  12. void testCase() {
  13. int n; cin >> n;
  14. map<int, int> mp;
  15. for (int i = 0; i < n; ++i) {
  16. int x; cin >> x;
  17. mp[x]++;
  18. }
  19. vector<pair<int, int>> a(mp.begin(), mp.end());
  20. sort(a.begin(), a.end(), cmp);
  21. for (auto i : a) {
  22. for (int j = 1; j <= i.second; ++j) {
  23. cout << i.first << " ";
  24. }
  25. }
  26. }
  27.  
  28. int main() {
  29. ios_base::sync_with_stdio(false);
  30. cin.tie(NULL); cout.tie(NULL);
  31.  
  32. int T = 1; cin >> T;
  33. while (T--) {
  34. testCase();
  35. cout << "\n";
  36. }
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout