- #include<bits/stdc++.h>
- using namespace std;
- vector<int> v;
- int main()
- {
- v.push_back(7);
- v.push_back(3);
- v.push_back(2);
- v.push_back(4);
- v.push_back(11);
- v.push_back(5);
- sort(v.begin(),v.end());
- for(int i:v)
- cout<<i<<" ";
- cout<<endl;
- auto it=lower_bound(v.begin(),v.end(),7);
- cout<<*it<<endl;
- it=upper_bound(v.begin(),v.end(),7);
- cout<<*it<<endl;
- cout<<*(--it)<<endl;
- cout<<*(++it)<<endl;
- cout<<it-v.begin()<<endl;
- it=find(v.begin(),v.end(), 2);
- it=find(v.begin(), v.end(), 12);
- if(it==v.end())
- cout<<"no"<<endl;
-
- return 0;
- }
複製代碼 |