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