码迷,mamicode.com
首页 > 编程语言 > 详细

排序~

时间:2019-01-31 19:20:22      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:rbegin   tor   ret   key   code   col   fir   class   span   

//vector的排序
vector<int>v;
sort(v.begin(),v.end());升序
sort(v.rbegin(),v,rend());降序


//sort of vector<pair<int,int> >v;
v.push_back({1,5});
v.push_back({2,3});
v.push_back({1,2});
sort(v.begin(), v.end());//输出{1,2},{1,5},{2,3}


//sort of vecto<tuple<int,int,int> > v;
v.push_back({2,1,4});
v.push_back({1,5,3});
v.push_back({2,1,3});
sort(v.begin(), v.end());
//有is~

  vector<pair<int,int> >v;很常用

 

还有一种写法

 1 void cmp(pair<int,int> a,pair<int,int> b)
 2 {
 3      if(a.first==b.first)return a.second<s.b.second;
 4       
 5      return a.first<b.first;
 6 }
 7 
 8 
 9 
10 pair<int,int> a,pair<int,int> b;
11 
12 sort(a,b,cmp);

 

//string
bool comp(string a, string b) {
    if (a.size() != b.size()) return a.size() < b.size();
    return a < b;
}


string s="monkey";
sort(s.begin(),s.end());//output:ekmnoy

 

排序~

标签:rbegin   tor   ret   key   code   col   fir   class   span   

原文地址:https://www.cnblogs.com/guaguastandup/p/10343113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!