- #include<bits/stdc++.h>
- using namespace std;
- set<int> s;
- int main()
- {
- s.insert(9);
- s.insert(2);
- s.insert(5);
- s.insert(2);
- s.insert(12);
- s.insert(7);
- cout<<s.size()<<endl;
- cout<<"-----"<<endl;
- for(int i:s)
- cout<<i<<endl;
- cout<<"-----"<<endl;
- for(auto it=s.begin();it!=s.end();it++)
- cout<<*it<<endl;
- cout<<"-----"<<endl;
- auto it=s.upper_bound(8);
- cout<<*it<<endl;
- cout<<*--it<<endl;
- cout<<"-----"<<endl;
- it=s.upper_bound(13);
- if(it==s.end())
- cout<<"no find"<<endl;
- else
- cout<<*it<<endl;
- it=--s.lower_bound(2);
- if(it==s.end())
- cout<<"no find"<<endl;
- else
- cout<<*it<<endl;
- return 0;
- }
複製代碼 |