AcWing 3213. 数字排序
原题链接
简单
作者:
把这题Ac了
,
2024-11-19 11:13:35
,
所有人可见
,
阅读 1
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
struct node{
int times,val;
}d[N];
int n;
bool cmp(node &a,node &b){
if(a.times != b.times) return a.times < b.times;
else{
return a.val > b.val;
}
}
int main(){
cin >> n;
int k = 0;
for(int i = 0;i < n;i++){
int t,flag = 1;
cin >> t;
for(int j = 0;j < k;j++){
if(d[j].val == t) d[j].times++,flag = 0;
}
if(flag){
d[k++] = {1,t};
}
}
sort(d,d + k,cmp);
for(int i = k - 1;i >= 0;i--){
cout << d[i].val << ' ' << d[i].times << endl;
}
}