设为首页 加入收藏

TOP

C++ set自定义排序规则(nyist 8)
2014-11-23 21:28:01 来源: 作者: 【 】 浏览:12
Tags:set 定义 排序 规则 nyist
C++的容器大多数都是自动排序的,所以你使用这些容器时,你加入的元素类型必须是可以比较大小的,如果不是,则需要自定义排序规则,例如你自定义的结构体:
#include 
#include 
using namespace std;
struct ju
{
	int id,x,y;
	bool operator <(const ju &a)const //排序并且去重复
	{
		if(id==a.id)
		{
			if(x==a.x) return y my; 
set ::iterator it; 
int main(int argc, char *argv[])
{
	int t,n,i,j;
	cin>>t;
	while(t--)
	{
		cin>>n; my.clear();
		for(i=0;i>tt.id>>tt.x>>tt.y;
			if(tt.x 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇130804组队练习赛ZOJ校赛 下一篇poj 1611 The Suspects(并查集)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)
·玩转C语言和数据结构 (2025-12-27 01:19:05)
·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)