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