一种排序
来源:互联网 发布:python commands模块 编辑:程序博客网 时间:2024/05/20 13:38
一种排序
时间限制:3000 ms | 内存限制:65535 KB
难度:3
- 描述
- 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复;还知道这个长方形的宽和长,编号、长、宽都是整数;现在要求按照一下方式排序(默认排序规则都是从小到大);
1.按照编号从小到大排序
2.对于编号相等的长方形,按照长方形的长排序;
3.如果编号和长都相同,按照长方形的宽排序;
4.如果编号、长、宽都相同,就只保留一个长方形用于排序,删除多余的长方形;最后排好序按照指定格式显示所有的长方形;- 输入
- 第一行有一个整数 0<n<10000,表示接下来有n组测试数据;
每一组第一行有一个整数 0<m<1000,表示有m个长方形;
接下来的m行,每一行有三个数 ,第一个数表示长方形的编号,
第二个和第三个数值大的表示长,数值小的表示宽,相等
说明这是一个正方形(数据约定长宽与编号都小于10000); - 输出
- 顺序输出每组数据的所有符合条件的长方形的 编号 长 宽
- 样例输入
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")); }}
0 0
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- 一种排序
- python—利用matplotlib库画图
- 两天了解scala
- Netty事件驱动总结
- 学习Spring Cloud第七课(Ribbon的基本使用)
- plsql连接远程数据库
- 一种排序
- 【spoj8222】Substrings 后缀自动机
- 冒泡排序、选择排序、插入排序、快速排序
- 找工作第二天
- 高性能的通讯库-ZeroMQ的几个高性能特征
- 16 利用scipy.misc等库对jpg以及png等图像数据预处理(用于深度学习喂数据)
- SQLserver中用convert函数转换日期格式
- Thymeleaf设置特定属性
- 80386registers