nyoj 8一种排序
来源:互联网 发布:淘宝定时上架有什么用 编辑:程序博客网 时间:2024/06/16 06:50
一种排序
时间限制: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
<span style="font-size:18px;">#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;# define maxn 1002struct node{ int b,z,k;}w[maxn];bool cmp(node x,node y){ if(x.b<y.b) return true; if(x.b==y.b&&x.z<y.z) return true; if(x.b==y.b&&x.z==y.z&&x.k<=y.k) return true; return false;}int main(){ int ncase,i,n,t; scanf("%d",&ncase); while(ncase--) { scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d %d",&w[i].b,&w[i].z,&w[i].k); if(w[i].z<w[i].k) { t=w[i].z; w[i].z=w[i].k; w[i].k=t; } } sort(w,w+n,cmp); for(i=0;i<n;i++) { if(w[i-1].b==w[i].b&&w[i-1].z==w[i].z&&w[i-1].k==w[i].k) { continue;//相同不输出。 } printf("%d %d %d",w[i].b,w[i].z,w[i].k); printf("\n"); } }}</span>
1 0
- NYOJ 8 一种排序
- NYOJ 8 一种排序
- NYOJ 8 一种排序
- NYOJ 8-一种排序
- NYOJ,8,一种排序
- NYOJ--8--一种排序
- nyoj-8-一种排序
- nyoj 8 一种排序
- 一种排序NYOJ 8
- NYOJ 8 一种排序
- NYOJ 8 一种排序
- 一种排序(nyoj 8)
- NYOJ 8 一种排序
- NYOJ 8 一种排序
- nyoj 8 一种排序
- nyoj 8 一种排序
- nyoj 8 一种排序
- nyoj 8 一种排序
- MySQL无法存储Emoji表情问题
- javascript面向对象编程
- Hello world
- gdb 调试
- android imageview
- nyoj 8一种排序
- Oracle提交和回滚处理
- fastcgi配置
- onMeasure()的9种情况
- 将真分数分解为埃及分数
- spi协议及工作原理分析(转载)
- pcDuino使用问题总结
- cocos2dx中精灵如何run一个动作
- 为什么在C语言中 3<x<5无论x取什么值,最终结果都为1