Skip to content

Instantly share code, notes, and snippets.

@uzumaki-narut0
Created May 27, 2017 10:49
Show Gist options
  • Save uzumaki-narut0/3a233627ff7ca49b2c1f888a995b5dc9 to your computer and use it in GitHub Desktop.
Save uzumaki-narut0/3a233627ff7ca49b2c1f888a995b5dc9 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
#define tr(c,it)\
for(typeof(c.begin()) = c.begin() ; it != c.end() ; it++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define present(c,x) (c.find(x) != c.end())
bool mycomp(pair<int, int> p1, pair<int, int> p2){
if(p1.first == p2.first)
return(p1.second > p2.second);
else return(p1.first<p2.first);
}
int main()
{
//code
int t;
cin>>t;
while(t--)
{
int n, i;
cin>>n;
vector<int> v1(n);
map<int, int> m1;
for(i=0 ; i<n ; i++)
{
cin>>v1[i];
if(present(m1, v1[i]))
m1[v1[i]] = m1[v1[i]] + 1;
else
m1[v1[i]] = 1;
}
map<int, int>::iterator it = m1.begin();
vector<pair<int, int> > v2;
for(; it != m1.end() ; it++)
{
v2.pb(make_pair(it->second, it->first));
}
sort(v2.rbegin(), v2.rend(), mycomp);
int x = v2.size();
for(i=0 ; i<x ; i++)
{
int frequency = v2[i].first;
int value = v2[i].second;
for(int j=0 ; j<frequency ; j++)
{
cout<<value<<" ";
}
}
cout<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment