现在的位置: 首页 > 综合 > 正文

运算符的重载—sort和unique

2013年06月28日 ⁄ 综合 ⁄ 共 480字 ⁄ 字号 评论关闭

运算符的重载是比较重要的内容,,

#include <stdio.h>
#include <iostream>
#include <algorithm>


using namespace std;


struct node{
	int a;
	int b;
	bool operator< (const node t)
	{
		if(this->a!=t.a)
			return a>t.a;
		else
			return this->b>t.b;
	}
	bool operator== (const node t)
	{
		return this->a==t.a&&this->b==t.b;
	}
}que[111];


int main()
{
	for(int i=0;i<2;i++)
	{
		scanf("%d%d",&que[i].a,&que[i].b);
	}
	sort(que,que+2);
	for(i=0;i<2;i++)
	{
		printf("%d %d\n",que[i].a,que[i].b);
	}

	int m=unique(que,que+2)-que;
	for(i=0;i<m;i++)
	{
		printf("%d %d\n",que[i].a,que[i].b);
	}
	return 0;
}

抱歉!评论已关闭.