zoukankan      html  css  js  c++  java
  • set基本用法-----2

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cmath>
     5 #include<vector>
     6 #include<algorithm>
     7 #include<cstring>
     8 #include<vector>
     9 #include<map>
    10 #include<stack>
    11 #include<set>
    12 #define maxn +50
    13 #define inf 0x7fffffff
    14 #define  xiao 1e-9
    15 using namespace std;
    16 set<int>::iterator iter;
    17 int main()
    18 {
    19     int a[]={1,2,3};
    20     set<int> s; 
    21     s.insert(a,a+3);//与set<int> s(a,a+3); 等效 
    22     //s.find()查找set中是否有这个数,iter是它的位置,如果有则返回iter ,没有则返回s.end();
    23     {
    24 
    25     if((iter=s.find(3))!=s.end())
    26     {
    27         cout<<*iter<<endl;
    28     }
    29     } 
    30     //insert(first,second) 把定位器first 与second之间的值插入set中 ,返回值为空 
    31     {
    32     for(iter=s.begin();iter!=s.end();++iter) cout<<*iter<<" ";
    33     cout<<endl;
    34 }
    35     //insert(key_value)返回值是pair<set<int>::iterator,bool>,bool代表是否插入成功,iterator代表插入的位置,若key_value已经在set中,则iterator返回所在位置 
    36     {
    37     pair<set<int>::iterator,bool> pr;
    38     pr=s.insert(5);
    39     if(pr.second) cout<<*pr.first<<endl; 
    40     }
    41     //lower_bound(key_value)返回第一个大于等于key_value的值的位置
    42     //upper_bound(key_value)返回最后一个大于等于key_value的值的位置
    43     {
    44         cout<<*s.lower_bound(2)<<endl;
    45         cout<<*s.upper_bound(2)<<endl;
    46     }
    47     return 0;
    48 }

    set真是一个神奇的东西~~~~~

  • 相关阅读:
    Compiere中的树
    Compiere 模型构建
    LSMW魔鬼教程
    Compiere 因翻译工作没有完成,所以现在系统中的所有帮助去掉
    插入、更新扩展字段
    SAPscript Forms 教程
    SAP ABAP 效率测试
    批量更新数据表
    月份的描述表T247
    SAP 程序下载工具
  • 原文地址:https://www.cnblogs.com/TYH-TYH/p/4929723.html
Copyright © 2011-2022 走看看