-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSORT12.cpp
46 lines (45 loc) · 980 Bytes
/
SORT12.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<int, int> &a,
const pair<int, int> &b)
{
if (a.second != b.second)
return a.second > b.second;
else
return a.first < b.first;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int a[n], b[61];
memset(b, 0, sizeof b);
for (int i = 0; i < n; i++)
{
cin >> a[i];
b[a[i]]++;
}
//author anas khan
vector<pair<int, int>> v;
for (int i = 0; i < 61; i++)
{
if (b[i] != 0)
{
v.push_back(make_pair(i, b[i]));
}
}
//sort(v.begin(),v.end());
sort(v.begin(), v.end(), comp);
for (int i = 0; i < v.size(); i++)
{
for (int j = 0; j < v[i].second; j++)
cout << v[i].first << " ";
}
cout << endl;
}
return 0;
}