请先读题!!!
以下是代码:
#include<iostream>
#include<algorithm>
using namespace std;
int n,top=-1;
struct S{
int x,y;
}a[500001],stack[500001];
bool cmp(S a,S b){
return a.x>b.x||(a.x==b.x&&a.y>b.y);
}
int main(){
cin>>n;
for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
sort(a,a+n,cmp);
int my=a[0].y;
stack[++top]=a[0];
for(int i=1;i<n;i++){
if(a[i].y>my){
my=a[i].y;
stack[++top]=a[i];
}
}
printf("(%d,%d)",stack[top].x,stack[top].y);
top--;
while(top>-1){
printf(",(%d,%d)",stack[top].x,stack[top].y);
top--;
}
return 0;
}
讲解在评论区,如有问题私信作者!!!