0% found this document useful (0 votes)
8 views2 pages

B23

Uploaded by

Linh Phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

B23

Uploaded by

Linh Phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

#include<algorithm>
#include<map>
using namespace std;
bool cmp1(pair<int,int> x, pair<int,int> y)
{
if(x.second != y.second)
return x.second>y.second;
else
{
return x.first<y.first;
}

}
bool cmp2(pair<int,int> x, pair<int,int> y)
{
return x.second>y.second;

}
void in(vector<pair<int,int>> v)
{
for(auto it : v)
{
cout<<it.first<<" ";
cout<<endl;
}
}

void s1(vector<pair<int,int>> v)
{
sort(v.begin(),v.end(),cmp1);
in(v);
}
void s2(vector<pair<int,int>> v)
{
sort(v.begin(),v.end(),cmp2);
in(v);
}

int main()
{
int n;cin>>n;
vector<pair<int,int>> v;
map<int,int> m;

for(int i=0;i<n;i++)
{
int x;cin>>x;
m[x]++;
pair<int,int> t;
t.first=x;
t.second=0;
v.push_back(t);
}
for(int i=0;i<n;i++)
{
int x = v[i].first;
v[i].second=m[x];

}
s1(v);
s2(v);

You might also like