map vector struct+sort
来源:互联网 发布:cms系统架构图 编辑:程序博客网 时间:2024/05/22 17:22
#include<map>#include <vector>#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#define MAXN 10using namespace std;typedef struct Node{ int x,y; string name; bool operator < (const Node & a) const{ /// http://bbs.csdn.net/topics/340163715 ///sort在实现的时候,里面用的是const对象,所以不能调用非const成员函数 return this->x < a.x; } Node(int x,int y,string name):x(x),y(y),name(name){} Node():x(0),y(0),name("NULL"){} /// start -std=c++11 friend ostream& operator << (ostream &os,Node a){ os<<"x:"<<a.x<<" y:"<<a.y<<" name:"<<a.name; return os; }}Node;vector<Node> node{{1,10,"a"},{11,100,"b"},{111,1000,"c"},{}};map<int,vector<Node>>m;vector<vector<int> >v1;vector<int>v2[10];vector<int>v3;int main(){ sort(node.begin(),node.end()); for(vector<Node>::iterator it = node.begin();it != node.end();it++) cout<<*it<<endl; cout<<"===================================================="<<endl; m[1].push_back(node[0]); m[1].push_back(node[1]); m[0].push_back(node[2]); for(map<int,vector<Node>>::iterator it = m.begin();it != m.end();it++){ cout<<it->first<<endl; for(vector<Node>::iterator itt = it->second.begin();itt != it->second.end();itt++) cout<<"\t"<<"-->"<<*itt<<endl; } cout<<"===================================================="<<endl; v3.push_back(1); /// 动态二维数组 v3.push_back(2); v3.push_back(3); v1.push_back(v3); v3.push_back(4); v1.push_back(v3); for(vector<vector<int>>::iterator it = v1.begin();it != v1.end();it++){ for(vector<int>::iterator itt = it->begin();itt != (*it).end();itt++) cout<<*itt<<" "; cout<<endl; } cout<<"===================================================="<<endl; return 0;}
0 0
- map vector struct+sort
- 对象管理器 3种方法实现 struct、 vector、map
- struct基础&通过struct和sort结合代替vector列排列
- [转]STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法(转)
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法收藏
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- STL中的常用的vector,map,set,Sort用法
- VS2010编译Boost 1.56 http://blog.csdn.net/kangroger/article/details/39393769
- SQL Server Management Studio数据库中的增删改查
- java web servlet来实现验证码的功能
- 进程与线程
- 自己写的第一个小程序,记录点滴
- map vector struct+sort
- SQL Server 增删改查等操作及举例
- 大整数乘法——分治法
- [PHP]使用array_merge重新排列数组下标
- POJ 1785 Binary Search Heap Construction [treap]
- hdu 5451 Best Solver (特征方程求通项+广义Fibonacci数列找循环节)
- HDU 5469 Clarke and problem (DP)
- CentOS 7.1 升级Python2.7.10及编译mod_wsgi指南
- iOS中的模糊效果