1 8 1 1 1 1 1 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1
1 1 1 1 2 1 1 2 2 2 1 1 2 2 1
我的代码:
#include <iostream> #include <algorithm> #include <set> using namespace std; struct S { int id; int h; int w; }; bool operator<(const S& r1,const S& r2) { return r1.id<r2.id || r1.id==r2.id && r1.h<r2.h ||r1.id==r2.id&&r1.h==r2.h &&r1.w<r2.w; } int main() { set<S> a; S p; int n,m; cin >> n; while (n--) { cin >> m; for (int i=0;i<m;++i) { cin >> p.id; cin >> p.h >> p.w; if (p.h<p.w) { swap(p.h,p.w); } a.insert(p); } set<S>::iterator it; for (it=a.begin();it!=a.end();++it) { cout << it->id << " " << it->h << " " << it->w ; cout << endl; } a.clear(); } return 0; }大神地址:http://blog.csdn.net/zcy20121105/article/details/8813138
参考的代码:
#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) { 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")); } }
原文地址:http://blog.csdn.net/zsc2014030403015/article/details/44307523