set的自定义排序

看下面的代码就好了

struct cmp{
	bool operator() (const pair<int,int>& a,const pair<int,int> &b)const{
		int lena=a.second-a.first+1;
		int lenb=b.second-b.first+1;
		if(lena==lenb)
		return a.first<b.first;
		return lena>lenb;
	}
};
int main()
{
set<pair<int,int>,cmp> t;
}
posted @ 2023-02-25 14:45  努力的德华  阅读(41)  评论(0)    收藏  举报