本帖最後由 許晏睿 於 2023-10-28 19:59 編輯
- #include<bits/stdc++.h>
- using namespace std;
- vector<int> v={2,5,7,6,4};//24567
- int main()
- {
- sort(v.begin(),v.end());
- for(int i:v)
- cout<<i<<" ";
- cout<<endl<<"=================="<<endl;
- auto it=lower_bound(v.begin(),v.end(),7);
- cout<<*it<<endl;
- cout<<"=================="<<endl;
- it=upper_bound(v.begin(),v.end(),4);//4
- cout<<*(--it)<<endl;
- it=lower_bound(v.begin(),v.end(),5);//6
- cout<<*(++it);
- cout<<endl<<"=================="<<endl;
- it=lower_bound(v.begin(),v.end(),6);//3
- cout<<it-v.begin()<<endl;
- it=find(v.begin(),v.end(),2);//0
- cout<<it-v.begin()<<endl;
- cout<<"=================="<<endl;
- it=find(v.begin(),v.end(),1);
- if(it==v.end())
- cout<<"no find"<<endl;
- return 0;
- }
複製代碼 |