用到了set容器的自动排序和去重的功能,注意定义排序规则的时候要使用const
ac代码
#include<set>
#include<iostream>
#include<algorithm>
using namespace std;
struct Rectrangle
{
int num,length,width;
Rectrangle(int num_,int length_,int width_)
{
num=num_;
length=length_;
width=width_;
}
bool operator < (Rectrangle a) const
{
if(num!=a.num)
{
return num<a.num;
}
else if(length!=a.length)
{
return length<a.length;
}
else
{
return width<a.width;
}
}
};
int main()
{
int n;
cin>>n;
while(n--)
{
int m,num,length,width;
cin>>m;
set<Rectrangle> rect;
set<Rectrangle>::iterator iter;
for(int i=0;i<m;i++)
{
cin>>num>>length>>width;
if(length<width)
{
swap(length,width);
}
rect.insert(Rectrangle(num,length,width));
}
for(iter=rect.begin();iter!=rect.end();iter++)
{
cout<<iter->num<<" "<<iter->length<<" "<<iter->width<<endl;
}
}
return 0;
}