返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<int> v;
  4. int main()
  5. {
  6.     v.push_pack(7);
  7.     v.push_pack(2);
  8.     v.push_pack(1);
  9.     v.push_pack(3);
  10.     v.push_pack(11);
  11.     v.push_pack(5);
  12.     sort(v.begin(), v.end());  
  13.     for(int i: v)
  14.         cout<<i<<" ";
  15.     cout<<endl;
  16.     cout<<"--------------"<<endl;
  17.     auto it=lower_bound(v.begin(), v.end(), 7);  
  18.     cout<<*it<<endl;
  19.     it=upper_bound(v.begin(), v.end(), 7);
  20.     cout<<*it<<endl;
  21.     cout<<"--------------"<<endl;
  22.     it=upper_bound(v.begin(), v.end(), 9);
  23.     cout<<*it<<endl;   
  24.     cout<<*(--it)<<endl;   
  25.     it=lower_bound(v.begin(), v.end(), 3);
  26.     cout<<*(++it)<<endl;   
  27.     cout<<"------------"<<endl;
  28.     it=lower_bound(v.begin(), v.end(), 3);
  29.     cout<<it-v.begin()<<endl;  
  30.     it=find(v.begin(), v.end(), 2);   
  31.     cout<<it-v.begin()<<endl;
  32.     cout<<"------------"<<endl;
  33.     it=find(v.begin(), v.end(), 12);   
  34.     if(it==v.end())
  35.         cout<<"no find"<<endl;
  36.     it=upper_bound(v.begin(), v.end(), 12);
  37.     if(it==v.end())
  38.         cout<<"no find"<<endl;
  39.     return 0;
  40. }
複製代碼

TOP

返回列表