结构体排序
程序员文章站
2024-03-21 19:12:04
...
结构体排序
会当击水三千里,自信人生二百年~~~
#include<iostream>
#include<algorithm>
using namespace std;
struct Node
{
int x,y;
};
int cmp(Node a,Node b)
{
if(a.x>b.x) return a.x>=b.x;
else if(a.x<b.x) return b.x<a.x;
else
{
if(a.y>=b.y) return a.y>=b.y;
else return a.y>=b.y;
}
}
int main()
{
struct Node node[20];
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>node[i].x>>node[i].y;
sort(node,node+n,cmp);
cout<<"nb"<<endl;
for(int i=0;i<n;i++)
{
cout<<node[i].x<<" "<<n ode[i].y;
cout<<endl;
}
return 0;
}