181 1 11 1 11 1 21 2 11 2 22 1 12 1 22 2 1样例输出1 1 11 2 11 2 22 1 12 2 1#include<iostream>#include<set>#include<iterator>using namespace std;struct Rect{ int num,length,width;};bool Operator<(const Rect& r1,const Rect& r2)//重载<用于排序{ return r1.num<r2.num || r1.num==r2.num && r1.length<r2.length ||r1.num==r2.num&&r1.length==r2.length &&r1.width<r2.width;}istream& operator>>(istream& in,Rect& r)//重载>>用于输入&返回stream类型引用{ in>>r.num; int a,b; cin>>a>>b; r.length=max(a,b); r.width=min(a,b); return in;}ostream& operator<<(ostream& out,const Rect& r){ return out<<r.num<<" "<<r.length<<" "<<r.width;}int main(){ int num; cin>>num; while(num--) { set<Rect> rs; Rect r; int n; cin>>n; while(n--) { cin>>r; rs.insert(r); } copy(rs.begin(),rs.end(),ostream_iterator<Rect>(cout,"/n")); }}
新闻热点
疑难解答