返回列表 發帖
本帖最後由 許晏睿 於 2023-10-28 19:59 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<int> v={2,5,7,6,4};//24567
  4. int main()
  5. {
  6.     sort(v.begin(),v.end());
  7.     for(int i:v)
  8.         cout<<i<<" ";
  9.     cout<<endl<<"=================="<<endl;
  10.     auto it=lower_bound(v.begin(),v.end(),7);
  11.     cout<<*it<<endl;
  12.     cout<<"=================="<<endl;
  13.     it=upper_bound(v.begin(),v.end(),4);//4
  14.     cout<<*(--it)<<endl;
  15.     it=lower_bound(v.begin(),v.end(),5);//6
  16.     cout<<*(++it);
  17.     cout<<endl<<"=================="<<endl;
  18.     it=lower_bound(v.begin(),v.end(),6);//3
  19.     cout<<it-v.begin()<<endl;
  20.     it=find(v.begin(),v.end(),2);//0
  21.     cout<<it-v.begin()<<endl;
  22.     cout<<"=================="<<endl;
  23.     it=find(v.begin(),v.end(),1);
  24.     if(it==v.end())
  25.         cout<<"no find"<<endl;
  26.     return 0;
  27. }
複製代碼

TOP

返回列表