zoukankan      html  css  js  c++  java
  • C++ 迭代器容器学习

    set的一个用法 。

    difference找差集

    union合并set

    intersection找到交集

    #include<iostream>
    #include<string>
    #include<set>
    #include<algorithm>
    #include<iterator>
    int main() {
        using namespace std;
        const int N = 6;
        string s1[N] = {"buffoon","thinkers","for","heavy","can","for"};
        string s2[N] = {"metal","any","food","elegant","deliver","for"};
        set<string>A(s1,s1 + N);
        set<string>B(s2,s2 + N);
        ostream_iterator<string,char> out(cout," ");
        cout << "get A:" ;
        copy(A.begin(),A.end(),out);
        cout << endl;
        cout << "set B:";
        copy(B.begin(),B.end(),out);
        cout << endl;
        
        cout << "union set a,b " << endl;
        set_union(A.begin(),A.end(),B.begin(),B.end(),out);
        cout << endl;
    
        cout << "inter a and b " << endl;
        set_intersection(A.begin(),A.end(),B.begin(),B.end(),out);
        cout << endl;
    
        cout << "difference of a and b " << endl;
        set_difference(A.begin(),A.end(),B.begin(),B.end(),out);
        cout << endl;
    
        set<string>C;
        cout << "Set C" << endl;
        set_intersection(A.begin(),A.end(),B.begin(),B.end(),insert_iterator<set<string> >(C,C.begin()));
        for (auto x : C) cout << x << " " ; cout << endl;
    
        string s3 = "hungry";
        C.insert(s3);
        cout << "Set C after insertion:
    ";
        copy(C.begin(),C.end(),out);
        cout << endl;
    
        cout << "show a range : 
    ";
        copy(C.lower_bound("ghost"),C.upper_bound("spook"),out);
        cout << endl;
    
        return 0;
    }
  • 相关阅读:
    <爬虫实例> 8684公交网-太原公交线路信息
    <爬虫> requests模块
    爬虫四 selenium + phantomjs & Headless Chrome
    爬虫三 bs4&xpath&jsonpath
    爬虫二 cookie&正则
    爬虫一 发请求&定制请求&异常处理&配置代理
    抽屉页面设计
    HTML标签及其属性
    Python之路 day3 高阶函数
    Python之路 day3 递归函数
  • 原文地址:https://www.cnblogs.com/Commence/p/5679226.html
Copyright © 2011-2022 走看看