首页 > 其他分享 >set的自定义排序

set的自定义排序

时间:2023-02-25 14:57:25浏览次数:34  
标签:lenb lena set const 自定义 int 排序

看下面的代码就好了

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;
}

标签:lenb,lena,set,const,自定义,int,排序
From: https://www.cnblogs.com/xyh-hnust666/p/17154411.html

相关文章