#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(int x,int y){
return x > y;
}
int main(){
int A[100L];
int n;
scanf("%d",&n);
for(int i = 0;i < n; i++)
scanf("%d",&A[i]);
sort(A,A + n,cmp);
for(int i = 0;i < n; i++)
printf("%d ", A[i]);
printf("\n");
}
优先队列
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
struct Man{
int x;
int y;
Man(int X = 0,int Y = 0){
x = X;
y = Y;
}
friend bool operator < (Man p,Man q){
if(p.x != q.x)
return p.x > q.x;
else
return p.y < q.y;
}
/*这个函数的意思就是比较2个Man的优先级的时候*/
/* a < b 代表 b的优先级 比a大, x 大的 优先级大,
如果x相同,y小的优先级大*/
};
int main(){
priority_queue<Man>M;
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++){
int x,y;
scanf("%d%d",&x,&y);
M.push(Man(x,y));
}
printf("============\n");
while(!M.empty()){
printf("%d %d\n",M.top().x,M.top().y);
M.pop();
}
return 0;
}