include<bits/stdc++.h>
define ll long long
using namespace std; ll n, s; string a[1000006]; bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b){ if(a.second==b.second) return a.first < b.first; return a.second < b.second; } int main(){ iosbase::syncwithstdio(0); cin.tie(0); cout.tie(0); cin>>n; vector<ll>v(n); for(ll i=0; i<n; i++)cin>>v[i]; unorderedmap<ll, ll>dem; for(ll i=0; i<n; i++)dem[v[i]]++; vector<pair<ll,ll>> tanso(dem.begin(), dem.end()); sort(tanso.begin(), tanso.end(), cmp); for(const auto& it : tanso) for(ll i=0; i<it.second; i++)cout<<it.first<<' '; } //input: | output: //8 | 9 5 5 6 6 4 4 4 //6 5 6 9 4 4 5 4 | <br /> //---------------------------------------------------------- //8 | 9 3 3 5 5 2 2 2 //5 9 5 3 2 2 3 2 |
Bình luận