C++ set自定义排序规则(nyist 8)
来源:互联网 发布:淘宝视频下载专用工具 编辑:程序博客网 时间:2024/06/05 16:50
http://blog.csdn.net/liang5630/article/details/9768703
C++的容器大多数都是自动排序的,所以你使用这些容器时,你加入的元素类型必须是可以比较大小的,如果不是,则需要自定义排序规则,例如你自定义的结构体:
- #include <iostream>
- #include <set>
- using namespace std;
- struct ju
- {
- int id,x,y;
- bool operator <(const ju &a)const //排序并且去重复
- {
- if(id==a.id)
- {
- if(x==a.x) return y<a.y;
- else return x<a.x;
- }
- else return id<a.id;
- }
- }tt;
- set<ju> my;
- set<ju> ::iterator it;
- int main(int argc, char *argv[])
- {
- int t,n,i,j;
- cin>>t;
- while(t--)
- {
- cin>>n; my.clear();
- for(i=0;i<n;i++)
- {
- cin>>tt.id>>tt.x>>tt.y;
- if(tt.x<tt.y) swap(tt.x,tt.y);
- my.insert(tt);
- }
- for(it=my.begin();it!=my.end();it++)
- cout<<(*it).id<<" "<<(*it).x<<" "<<(*it).y<<endl;
- }
- return 0;
- }
0 0
- C++ set自定义排序规则(nyist 8)
- C++ set自定义排序规则(nyist 8)
- nyist 8(一种排序)
- 自定义比较优先级的set:TreeSet(有序(按照某种规则排序),唯一)
- set改变排序规则
- 还是nyist 8(一种排序)
- Set容器的排序规则
- Collections 自定义排序规则(实用)
- taleview排序自定义规则
- 自定义规则排序
- mysql 自定义排序规则
- 自定义排序规则
- (c++)关于stl里set容器的自定义排序
- (c++)关于stl里set容器的自定义排序
- (c++)关于stl里set容器的自定义排序
- C/C++--set排序
- C++ map 自定义排序规则
- Solr打分排序规则自定义
- java与C++之间进行SOCKET通讯要点简要解析
- 在系统中增加一个可唤醒中断--同时说明platform_device &platform_driver
- RAW
- Ext JS 4官方指南(一)——开始使用Ext JS 4
- vs2008下配置第三方库的注意事项
- C++ set自定义排序规则(nyist 8)
- Storm集群搭建
- javascript高级程序设计之数值转换
- 自定义控件一百行代码实现微信朋友圈九宫格图片显示
- 11.2 RAC环境OCR和Votedisk损坏丢失恢复
- 简单理解混淆矩阵
- codefores 392B Tower of Hanoi (记忆搜索)
- 通过servletcontext读取WEB-INF下的配置文件
- 立方体路径数