zoukankan      html  css  js  c++  java
  • set 学习笔记

    1. set 常用功能

    /****************************************
    * File Name: set.cpp
    * Author: sky0917
    * Created Time: 2014年06月 4日 18:47:22
    ****************************************/
    #include <map>
    #include <set>
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int main(){
        vector<int> ivec;
        for (int i = 0; i != 10; ++i){
            ivec.push_back(i);
            ivec.push_back(i);
        }    
        set<int> iset(ivec.begin(), ivec.end());
        cout<<ivec.size()<<endl;
        cout<<iset.size()<<endl;
        
        set<string> iset2;
        iset2.insert("the");
        iset2.insert("and");
        iset2.insert("3");
        iset2.insert("1");
        iset2.insert("2");
        iset2.insert("2");
        cout<<"size of iset2 = "<<iset2.size()<<endl;    
    // set 元素删除
    iset2.erase("2");
    // 遍历 set for (set<string>::iterator it = iset2.begin(); it != iset2.end(); ++it){ cout<<*it<<endl; } pair<set<string>::iterator, bool> pa = iset2.insert("zz"); cout << *pa.first<<endl; // 查找元素 if (iset.find(1) != iset.end()){ cout<<"find "<<1<<endl; } if (iset.count(2)) cout<<"count 2: "<<1<<endl; if (iset.count(11) == 0) cout<<"count 11: "<<0<<endl; /* set 中的元素是不可以被修改的! * set<string>::iterator it = iset2.find("zz"); * *it = "ss"; // error */ return 0; }
  • 相关阅读:
    hdu_2224_The shortest path(dp)
    hdu_4824_Disk Schedule(dp)
    hdu_5680_zxa and set(想法题)
    hdu_5683_zxa and xor(非正解的暴力)
    hdu_1429_胜利大逃亡(续)(BFS状压)
    hdu_1254_推箱子(双BFS)
    hdu_1969_pie(二分)
    hdu_2446_Shell Pyramid(数学,二分)
    hdu_2141_Can you find it?(二分)
    5.2 nc + JMX查看分布式程序数据
  • 原文地址:https://www.cnblogs.com/sky0917/p/3768545.html
Copyright © 2011-2022 走看看